问题
The clang diagnostics reference uses the word emit four times. The following warnings use this term.
Example 1: Compile this with -Wunneeded-internal-declaration -Wunneeded-member-function:
namespace {
int x;
int F ();
struct A {
void M ();
};
}
decltype (x) global1;
decltype (F ()) global2;
decltype (&A::M) global3;
You get the following warnings:
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
Example 2: Compile this with -Wweak-vtables -Wweak-template-vtables:
class Apple {
virtual ~Apple () {}
};
template <class T>
class Pear {
virtual void Foo () {}
};
template class Pear<void>;
You get the following warnings:
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
Question
What does emitting mean?
The most straightforward explanation would be: emitting = generating assembly code. But there are some open questions, if we examine the details.
- In example 1 if we do not use
x,FandA::Min unevaluated context, the warnings disappear. So the warning has to do something with unevaluated context. - In example 1
FandMare only declarations. Compiler never generates assembly code from a function declaration. So there is no point in giving a warning about it. - Clang has separate warnings for the case when a variable or function can be proven not to be used. Compile with
-Wunused(example). No assembly code is generated from the variable and the function, and the warnings do not use the term emit. - The warnings that come from
-Wunusedare reported for definitions and not declarations.
I do not fully understand example 2. I put it here for the sake of completeness. Emitting might mean a slightly different thing here.
Could someone, maybe a clang contributor give some clarification about these questions?
来源:https://stackoverflow.com/questions/58274145/clang-what-does-emitting-mean