c++ - 打印实例链

标签 c++ debugging instantiation typename

我正在使用 STL C++0x 容器调试一些 C++ 解析器(工具链是 GCC 4.7.0)。

而且由于 STL 重新绑定(bind)代码很难理解,我需要以某种方式打印 typedef 的完整实例化链,如 std::vector<T>::reference .当然,它只解析为 T& , 但在它通过 __gnu_cxx 中的至少 7 个不同模板之前和其他内部结构。

因此,我期待在模板错误的情况下打印出类似的内容,但对于编译器实例化的每个类。 可能吗? GCC 插件,也许...

UPD:好吧,我已经手动实例化了所有必需的模板。似乎没有什么好的方法可以自动执行此操作,除了将一些调试 printf 语句插入 GCC 代码本身。

最佳答案

由于您使用的是 GCC 4.7,我假设您使用的系统可以针对您的代码运行 clang。 Clang 的错误消息,特别是模板的错误消息非常好。


    template
    class Example {
        Example(const T& t) : t_(t) {}
        T& t_;
    };

    int a;
    Example e(a);

输出:


    t.cpp:8:14: error: calling a private constructor of class 'Example'
    Example e(a);
                 ^
    t.cpp:3:5: note: implicitly declared private here
        Example(const T& t) : t_(t) {}
        ^
    t.cpp:3:27: error: binding of reference to type 'int' to a value of type 'const int' drops
          qualifiers
        Example(const T& t) : t_(t) {}
                              ^  ~
    t.cpp:8:14: note: in instantiation of member function 'Example::Example' requested here
    Example e(a);
                 ^
    2 errors generated.

关于c++ - 打印实例链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10396753/

相关文章:

c++ - 是否可以在服务器 Linux 发行版上观察正在运行的 C++ 应用程序的持续 CPU 和内存使用情况?

c++ - 虚拟表的顺序重要吗?

javascript - 在 Chrome 开发者工具中禁用脚本编辑

mysql - 如何找到拥有本地 Sleeping MySQL 连接的 Unix 进程?

c# - 我对类(class)感到困惑

c++ - 优化 C++ 代码以提高性能

c# - 调试时 VS2012 的 VSIX 扩展未运行

Java : Instantiating method variables

c++ - 将函数标记为虚拟会导致 unique_ptr 出现编译器错误

c++ - 如何使用 Doxygen 记录 C++ 函数中的局部变量