C++ 叮当声:什么意思?
这个词用了四次。以下警告使用此术语 :使用C++ 叮当声:什么意思?,c++,clang,C++,Clang,这个词用了四次。以下警告使用此术语 :使用-wunneed内部声明-wunneed成员函数: namespace { int x; int F (); struct A { void M (); }; } decltype (x) global1; decltype (F ()) global2; decltype (&A::M) global3; 您将收到以下警告: warning: variable
-wunneed内部声明-wunneed成员函数
:
namespace {
int x;
int F ();
struct A {
void M ();
};
}
decltype (x) global1;
decltype (F ()) global2;
decltype (&A::M) global3;
您将收到以下警告:
warning: variable 'x' is not needed and will not be emitted
warning: function 'F' is not needed and will not be emitted
warning: member function 'M' is not needed and will not be emitted
warning: 'Apple' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit
warning: explicit template instantiation 'Pear<void>' will emit a vtable in every translation unit
:使用-Wweak vtables
-Wweak模板vtables
编译此文件:
class Apple {
virtual ~Apple () {}
};
template <class T>
class Pear {
virtual void Foo () {}
};
template class Pear<void>;
苹果类{
虚拟~Apple(){}
};
模板
梨类{
虚拟void Foo(){}
};
模板类;
您将收到以下警告:
warning: variable 'x' is not needed and will not be emitted
warning: function 'F' is not needed and will not be emitted
warning: member function 'M' is not needed and will not be emitted
warning: 'Apple' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit
warning: explicit template instantiation 'Pear<void>' will emit a vtable in every translation unit
警告:“Apple”没有越界的虚拟方法定义;它的vtable将在每个翻译单元中发出
警告:显式模板实例化“Pear”将在每个翻译单元中发出vtable
问题
发射意味着什么
最直接的解释是:emitting=生成汇编代码。但如果我们仔细研究一下细节,还有一些悬而未决的问题
- 在示例1中,如果我们在未计算的上下文中不使用
x
、F
和A::M
,警告将消失。因此,警告必须与未计算的上下文相关
- 在示例1中,
F
和M
只是声明。编译器从不从函数声明生成汇编代码。因此,没有必要就此发出警告
- 当可以证明某个变量或函数未被使用时,Clang有单独的警告。使用
-Wunused
()编译。变量和函数不会生成汇编代码,警告也不会使用术语emit
- 来自
-Wunused
的警告是针对定义而非声明报告的
我不完全理解示例2。我把它放在这里是为了完整。发射在这里可能意味着稍微不同的事情
有人,可能是一个铿锵的贡献者,能对这些问题做出一些澄清吗?可能只是一个疏忽,因为在这个上下文中发出的肯定意味着“代码生成”“尝试编译”。不能是程序,因为没有主功能。你也没有帮助自己多次问同一个问题。至少提供一个有机会编译的最小示例。使用术语“排放/已排放”。它似乎意味着写入对象文件。