自动成员函数调试符号错误的解决方法是什么?

8
似乎调试符号和自动模式存在问题。
我有一个类中的自动函数:
#include <cstddef>

template <typename T>
struct binary_expr {
    auto operator()(std::size_t i){
        return 1;
    }
};

int main(){
    binary_expr<double> b;
    return 0;
}

当我使用G++(4.8.2)和-g编译时,我遇到了这个错误:
g++ -g -std=c++1y auto.cpp
auto.cpp: In instantiation of ‘struct binary_expr<double>’:
auto.cpp:11:25:   required from here
auto.cpp:4:8: internal compiler error: in gen_type_die_with_usage, at dwarf2out.c:19484
 struct binary_expr {
        ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.gentoo.org/> for instructions.

使用clang++ (3.4)和-g选项,我得到了以下结果:

clang++ -g -std=c++1y auto.cpp
error: debug information for auto is not yet supported
1 error generated.

如果我删除-g或明确设置类型,则它可以完美运行。
clang++不应该是C++14功能完整的吗?
这些限制是否有解决方法,还是我已经失败了?

我假设您想要从您的operator()返回一个T,如果是这种情况,那么我不认为有任何理由使编译器推断返回类型。为什么不明确声明T作为返回类型呢? - Shoe
3
适用于gcc 4.9编译。至于clang是否功能完整,发出调试信息不是语言功能。 - Praetorian
@Jeffrey 这只是一个简化的情况,在我想要的情况下,并不是一个 T,如果不使用 auto,则推导可能会复杂。 - Baptiste Wicht
2个回答

2

现在这似乎可以在Clang 3.5 SVN上运行。实时示例。看起来罪魁祸首是2013年5月的提交,参见Clang邮件列表中的消息

PR16091: 尝试为未推断的自动返回类型发出调试信息时出错

也许我们应该只是禁止它而不是报错,但既然我们有了这个基础设施,我认为我应该使用它 - 如果确定这不是正确的事情,我们可能应该完全删除该基础设施。 我想这是从实现调试信息支持的早期留下的东西。

// RUN: %clang_cc1 -emit-llvm-only -std=c++1y -g %s 2>&1 | FileCheck %s
2   
3   struct foo {
4     auto func(); // CHECK: error: debug information for auto is not yet supported
5   };
6   
7   foo f;

然而,我找不到删除此信息的提交记录,可能是由于某种改进,现在已经防止触发此行为。


4
实际上不是,它似乎仍未修复。你提供的测试案例版本确实可行,但如果删除b(0)实例化,它就会再次出错:http://coliru.stacked-crooked.com/a/4e40517a78fedd48。 - akim

0

即使过了一段时间,我唯一找到的解决方法是将函数模板化,这个解决方法相当愚蠢... 显然,clang对于模板自动函数没有问题。我不知道这是否适用于每种情况,但到目前为止,它对我起作用了。

#include <cstddef>

template <typename T>
struct binary_expr {
    template<typename E = void>
    auto operator()(std::size_t i){
        return 1;
    }
};

int main(){
    binary_expr<double> b;
    return 0;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接