clang: What does emitting mean?

て烟熏妆下的殇ゞ 提交于 2019-12-22 14:45:07

问题


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, F and A::M in unevaluated context, the warnings disappear. So the warning has to do something with unevaluated context.
  • In example 1 F and M are 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 -Wunused are 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!