[cfe-dev] static constexpr member function of a local struct in a function template is instantiated too late

Michael Park mcypark at gmail.com
Tue Aug 12 20:09:27 PDT 2014


Hello,

I'm new to clang development and was hoping to get some help in tackling
this bug that I found/filed: http://llvm.org/bugs/show_bug.cgi?id=20625

Example:

template <typename T>
> void F() {
>   struct Num {
>     static constexpr int Get() { return 42; }
>   };
>   constexpr int n = Num::Get();
> }
> int main() {
>   F<int>();
> }


The summary of the issue is that the local struct *Num* and its static
constexpr function *Get* is not yet instantiated when we validate the
constexpr variable initialization of *n* during *F*'s instantiation.

More details:

*Num* and *Get* gets added to *PendingLocalImplicitInstantiations* in
*SubstStmt* at *SemaTemplateInstantiationDecl.cpp:3437*, and is
instantiated later by *PerformPendingInstantiations* at
*SemaTemplateInstantiationDecl.cpp:3458*. However, the validation of the
constexpr variable initialization of *n* happens in *SubstStmt* at which
point we don't yet have the definition of *Get* instantiated.

I'm not exactly sure what the correct approach would be to solve the
problem. It seems that the local implicit instantiations need to be
performed earlier, or the validation of constexpr variables need to be
delayed.

If someone can point me in the right direction it would be appreciated.

Thanks,

Michael Park
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140812/674ae78a/attachment.html>


More information about the cfe-dev mailing list