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

Michael Park mcypark at gmail.com
Wed Aug 20 12:20:00 PDT 2014


ping


On 12 August 2014 23:09, Michael Park <mcypark at gmail.com> wrote:

> 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/20140820/a1f3bb94/attachment.html>


More information about the cfe-dev mailing list