diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-05-11 23:09:06 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-05-11 23:09:06 +0000 |
commit | b0b68010c5da4828c5a43d8a85f8f3b2de65a3c9 (patch) | |
tree | cfcb7bb90ad8e4f841414f228f214165df1846ba /clang | |
parent | cc14f387e83bc4d542a0e510fead7b736ad70282 (diff) | |
download | bcm5719-llvm-b0b68010c5da4828c5a43d8a85f8f3b2de65a3c9.tar.gz bcm5719-llvm-b0b68010c5da4828c5a43d8a85f8f3b2de65a3c9.zip |
PR20625: Instantiate static constexpr member function of a local struct in a function template earlier.
This is necessary in order to allow the use of a constexpr member function, or
a member function with deduced return type, of a local class within a
surrounding instantiated function template specialization.
Patch by Michael Park!
This re-commits r236063, which was reverted in r236134, along with a fix for a
delayed template parsing bug that was exposed by this change.
llvm-svn: 237064
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Parse/ParseTemplate.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 | ||||
-rw-r--r-- | clang/test/SemaTemplate/instantiate-local-class.cpp | 15 |
3 files changed, 26 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index 53de72cd3cc..f1467fe553a 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -14,6 +14,7 @@ #include "clang/Parse/Parser.h" #include "RAIIObjectsForParser.h" #include "clang/AST/ASTConsumer.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/DeclTemplate.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Sema/DeclSpec.h" @@ -1301,7 +1302,8 @@ void Parser::ParseLateTemplatedFuncDef(LateParsedTemplate &LPT) { TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); // To restore the context after late parsing. - Sema::ContextRAII GlobalSavedContext(Actions, Actions.CurContext); + Sema::ContextRAII GlobalSavedContext( + Actions, Actions.Context.getTranslationUnitDecl()); SmallVector<ParseScope*, 4> TemplateParamScopeStack; diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index a0e8c2373da..4a92efdaae2 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1302,11 +1302,19 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { // DR1484 clarifies that the members of a local class are instantiated as part // of the instantiation of their enclosing entity. if (D->isCompleteDefinition() && D->isLocalClass()) { + Sema::SavePendingLocalImplicitInstantiationsRAII + SavedPendingLocalImplicitInstantiations(SemaRef); + SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs, TSK_ImplicitInstantiation, /*Complain=*/true); + SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs, TSK_ImplicitInstantiation); + + // This class may have local implicit instantiations that need to be + // performed within this scope. + SemaRef.PerformPendingInstantiations(/*LocalOnly=*/true); } SemaRef.DiagnoseUnusedNestedTypedefs(Record); diff --git a/clang/test/SemaTemplate/instantiate-local-class.cpp b/clang/test/SemaTemplate/instantiate-local-class.cpp index 3365c374072..ff6cf7923f1 100644 --- a/clang/test/SemaTemplate/instantiate-local-class.cpp +++ b/clang/test/SemaTemplate/instantiate-local-class.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -verify -std=c++11 %s +// RUN: %clang_cc1 -verify -std=c++11 -fdelayed-template-parsing %s + template<typename T> void f0() { struct X; @@ -342,3 +344,16 @@ namespace PR18653 { }; template struct S06<int>; } + +namespace PR20625 { +template <typename T> +void f() { + struct N { + static constexpr int get() { return 42; } + }; + constexpr int n = N::get(); + static_assert(n == 42, "n == 42"); +} + +void g() { f<void>(); } +} |