Fixes http://llvm.org/bugs/show_bug.cgi?id=20625
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>(); }
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits