使用自动成员函数解决调试符号错误的方法



调试符号和auto似乎有问题。

我在类中有一个auto函数:

#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功能完整的吗?

是否有解决这些限制的方法,或者我完蛋了?

这似乎可以在Clang 3.5 SVN上工作。<<strong>生活例子/strong>。罪魁祸首似乎是2013年5月的一次提交,请参阅Clang邮件列表中的消息

PR16091:试图为未推导的auto发出调试信息时出错返回类型

也许我们应该抑制这一点,而不是错误,但既然我们有基础设施,我想我会用它,如果这是确定这不是正确的东西我们应该把它去掉基础设施完全。我猜它从早期就在那里实现调试信息支持。

// 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;

然而,我找不到删除这个信息的提交,也许有一个改进,现在可以防止这个行为被触发

即使过了一段时间,我发现唯一的解决方案是使函数模板,相当愚蠢的解决方案…显然,clang对于模板化的auto函数没有问题。我不知道这是否适用于所有情况,但到目前为止,它对我来说是有效的。

#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;
}

最新更新