c++ - 避免对仅在源文件中定义的类发出弱虚表警告

标签 c++ clang qt-creator vtable

据我所知,一个类类至少需要一个在源文件(out of line)中定义的虚函数,否则将需要将 vtable 插入到每个目标文件中。

我有以下情况:

//foo.cpp

struct Foo {
virtual int Bar() { return 1; }
virtual ~Foo() = default;
};

Qt Creator (4.5.2) 中的 clang 代码模型为 Foo 发出 -Wweak-table 警告。
严格来说警告是正确的,因为 vtable 将包含在每个翻译单元中。实际上,它毫无值(value),因为无论如何 vtable 都只会在 foo.o 中发出。

如何仅对源文件中定义的类禁用 -Wweak-vtables?

最佳答案

事实证明,standalone clang 默认情况下是正确的,只有 Qt creator 中的 clang 代码模型显示无用警告。它已被报告为 QTCREATORBUG-19741 ,所以除了等待更新的 Qt Creator 版本之外别无他法。

关于c++ - 避免对仅在源文件中定义的类发出弱虚表警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50463374/

相关文章:

c++ - 使用 GetDIBits 函数对 _imp__GetDIBits@28 的 undefined reference

c++ - "error: invalid operands to binary expression"来自字符串库组件内部

c++ - Clang++ 编译器 - python 的模拟

c++ - Windows 上的 Clang 和 CMake - clang.exe 损坏,程序不可执行

c++ - 为什么在使用 Qt Creator 用 C 语言编译代码时出现错误,但使用 make 文件可以轻松做到这一点?

c++ - C++ 应用程序中的持久数据/设置

c++ - 将 C++ 引用包装到 C API 中

qt-creator - Qt Creator 中的 Valgrind

c++ - 将 Makefile 选项添加到 qtcreator 项目中

c# - 将托管程序合并到非托管 C++ 可执行文件中