Calling constexpr in default template argument

后端 未结 2 1709
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 01:40

In C++11 I am using a constexpr function as a default value for a template parameter - it looks like this:

template 
struct bar
{
    static         


        
2条回答
  •  情深已故
    2020-12-04 02:17

    Richard Smith (zygoloid) at the LLVM IRC channel had a short talk with me about this issue which is your answer

     hello folks
     zygoloid, what should happen in this case?
     http://stackoverflow.com/questions/10721130/calling-constexpr-in-default-template-argument
     it seems to be clang's behavior is surprising
     zygoloid, i cannot apply the "point of instantiation" rule to constexpr 
      function templates. if i call such a function template, the called definition's 
      POI often is *after* the specialization reference, which means at the point of 
      the call, the constexpr function template specialization is "undefined".
     it's a horrible mess. Clang does not do what the standard intends, but 
      as you note, the actual spec is gloriously unclear
     :(
     we should instantiate bar<3>::get(), because it is odr-used, but we 
      don't, because we incorrectly believe it's used in an unevaluated context
     conversely, the point of instantiation is too late :/
     PR11851
    

    So it seems that sometimes, Clang instantiates called function templates or member function of class templates but their instantiation is too late for the call to see, and at other cases it doesn't even instantiate them because it thinks it will never need them (unevaluated context).

提交回复
热议问题