Are all constexpr variable implicitly inline?

后端 未结 1 1898
有刺的猬
有刺的猬 2021-02-04 16:51

I was playing around with auto template parameters and I was surprised that this code didn\'t compiled:

constexpr auto bar = 2;

template

        
相关标签:
1条回答
  • 2021-02-04 17:24

    Are all constexpr variable implicitly inline?

    No. Only constexpr functions and constexpr static data members are implicitly inline ([dcl.constexpr]/1).

    Also, how does that affect the linkage of my variable bar?

    A constexpr variable is const ([dcl.constexpr]/9). A non-inline const variable that is not explicitly declared extern has internal linkage ([basic.link]/3).

    0 讨论(0)
提交回复
热议问题