Instantiate local class at the end of its definition
Michael Park
mcypark at gmail.com
Fri Aug 22 02:41:10 PDT 2014
Fixes http://llvm.org/bugs/show_bug.cgi?id=20625
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140822/650e7c59/attachment.html>
-------------- next part --------------
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 747eaf6..18b682e 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1190,6 +1190,10 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
/*Complain=*/true);
SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs,
TSK_ImplicitInstantiation);
+ // A static constexpr member function of a local class can be used in
+ // a constexpr expression right after the local class' definition.
+ // We need to instantiate them now, otherwise it may be too late.
+ SemaRef.PerformPendingInstantiations(/*LocalOnly=*/true);
}
return Record;
}
diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp
index c9897b9..58f1612 100644
--- a/test/SemaTemplate/instantiate-local-class.cpp
+++ b/test/SemaTemplate/instantiate-local-class.cpp
@@ -194,3 +194,15 @@ struct B {
void f() { F<int>(); }
};
}
+
+namespace PR20625 {
+ template <typename T>
+ void f() {
+ struct Num {
+ static constexpr int get() { return 42; }
+ };
+ constexpr int n = Num::get();
+ static_assert(n == 42, "n == 42");
+ }
+ void g() { f<int>(); }
+}
More information about the cfe-commits
mailing list