diff options
| author | John McCall <rjmccall@apple.com> | 2010-04-29 00:35:03 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-04-29 00:35:03 +0000 |
| commit | 80e58cd3e942f821c0c78d43ce93f8ecc39e30ea (patch) | |
| tree | 9ba86109427fa7501d2d137136636aa14f7b9b5e /clang/lib/Sema | |
| parent | d17020676106cd77cd35d263c5549b605dad0225 (diff) | |
| download | bcm5719-llvm-80e58cd3e942f821c0c78d43ce93f8ecc39e30ea.tar.gz bcm5719-llvm-80e58cd3e942f821c0c78d43ce93f8ecc39e30ea.zip | |
Properly switch into the declaring scope of a template when performing
template argument deduction or (more importantly) the final substitution
required by such deduction. Makes access control magically work in these
cases.
Fixes PR6967.
llvm-svn: 102572
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 24 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateDeduction.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 5 |
3 files changed, 32 insertions, 3 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index f6af46eca9a..02a86cd94db 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -233,6 +233,30 @@ public: /// CurContext - This is the current declaration context of parsing. DeclContext *CurContext; + /// A RAII object to temporarily push a declaration context. + class ContextRAII { + private: + Sema &S; + DeclContext *SavedContext; + + public: + ContextRAII(Sema &S, DeclContext *ContextToPush) + : S(S), SavedContext(S.CurContext) { + assert(ContextToPush && "pushing null context"); + S.CurContext = ContextToPush; + } + + void pop() { + if (!SavedContext) return; + S.CurContext = SavedContext; + SavedContext = 0; + } + + ~ContextRAII() { + pop(); + } + }; + /// PackContext - Manages the stack for #pragma pack. An alignment /// of 0 indicates default alignment. void *PackContext; // Really a "PragmaPackStack*" diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 0a2c5ae00e0..13bfc0fdf9e 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -988,6 +988,8 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, if (Inst) return TDK_InstantiationDepth; + ContextRAII SavedContext(*this, Partial->getDeclContext()); + // C++ [temp.deduct.type]p2: // [...] or if any template argument remains neither deduced nor // explicitly specified, template argument deduction fails. @@ -1163,6 +1165,8 @@ Sema::SubstituteExplicitTemplateArguments( if (Inst) return TDK_InstantiationDepth; + ContextRAII SavedContext(*this, FunctionTemplate->getDeclContext()); + if (CheckTemplateArgumentList(FunctionTemplate, SourceLocation(), ExplicitTemplateArgs, @@ -1311,6 +1315,8 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, if (Inst) return TDK_InstantiationDepth; + ContextRAII SavedContext(*this, FunctionTemplate->getDeclContext()); + // C++ [temp.deduct.type]p2: // [...] or if any template argument remains neither deduced nor // explicitly specified, template argument deduction fails. diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 6fdf243d7bb..7dee0ad99bf 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1167,8 +1167,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. - DeclContext *PreviousContext = CurContext; - CurContext = Instantiation; + ContextRAII SavedContext(*this, Instantiation); // If this is an instantiation of a local class, merge this local // instantiation scope with the enclosing scope. Otherwise, every @@ -1209,7 +1208,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, Invalid = true; // Exit the scope of this instantiation. - CurContext = PreviousContext; + SavedContext.pop(); // If this is a polymorphic C++ class without a key function, we'll // have to mark all of the virtual members to allow emission of a vtable |

