diff options
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index bc46aae0a6b..c5836746221 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2920,15 +2920,21 @@ void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old, /// definitions here, since the initializer hasn't been attached. /// void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous, - bool MergeTypeWithPrevious) { + bool IsVariableTemplate, bool MergeTypeWithPrevious) { // If the new decl is already invalid, don't do any other checking. if (New->isInvalidDecl()) return; - // Verify the old decl was also a variable. + // Verify the old decl was also a variable or variable template. VarDecl *Old = 0; - if (!Previous.isSingleResult() || - !(Old = dyn_cast<VarDecl>(Previous.getFoundDecl()))) { + if (Previous.isSingleResult() && + (Old = dyn_cast<VarDecl>(Previous.getFoundDecl()))) { + if (IsVariableTemplate) + Old = Old->getDescribedVarTemplate() ? Old : 0; + else + Old = Old->getDescribedVarTemplate() ? 0 : Old; + } + if (!Old) { Diag(New->getLocation(), diag::err_redefinition_different_kind) << New->getDeclName(); Diag(Previous.getRepresentativeDecl()->getLocation(), @@ -4919,6 +4925,7 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, bool IsExplicitSpecialization = false; bool IsVariableTemplateSpecialization = false; bool IsPartialSpecialization = false; + bool IsVariableTemplate = false; bool Invalid = false; // TODO: Can we remove this (error-prone)? TemplateParameterList *TemplateParams = 0; VarTemplateDecl *PrevVarTemplate = 0; @@ -5019,6 +5026,7 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, } else { // if (TemplateParams->size() > 0) // This is a template declaration. + IsVariableTemplate = true; // Check that we can declare a template here. if (CheckTemplateDeclScope(S, TemplateParams)) @@ -5310,9 +5318,11 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, LookupResult PrevDecl(*this, GetNameForDeclarator(D), LookupOrdinaryName, ForRedeclaration); PrevDecl.addDecl(PrevVarTemplate->getTemplatedDecl()); - D.setRedeclaration(CheckVariableDeclaration(NewVD, PrevDecl)); + D.setRedeclaration( + CheckVariableDeclaration(NewVD, PrevDecl, IsVariableTemplate)); } else - D.setRedeclaration(CheckVariableDeclaration(NewVD, Previous)); + D.setRedeclaration( + CheckVariableDeclaration(NewVD, Previous, IsVariableTemplate)); } // This is an explicit specialization of a static data member. Check it. @@ -5340,8 +5350,8 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, } } - // If this is not a variable template, return it now - if (!TemplateParams || IsVariableTemplateSpecialization) + // If this is not a variable template, return it now. + if (!IsVariableTemplate) return NewVD; // If this is supposed to be a variable template, create it as such. @@ -5745,7 +5755,8 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { /// /// Returns true if the variable declaration is a redeclaration. bool Sema::CheckVariableDeclaration(VarDecl *NewVD, - LookupResult &Previous) { + LookupResult &Previous, + bool IsVariableTemplate) { CheckVariableDeclarationType(NewVD); // If the decl is already known invalid, don't check it. @@ -5795,7 +5806,7 @@ bool Sema::CheckVariableDeclaration(VarDecl *NewVD, filterNonConflictingPreviousDecls(Context, NewVD, Previous); if (!Previous.empty()) { - MergeVarDecl(NewVD, Previous, MergeTypeWithPrevious); + MergeVarDecl(NewVD, Previous, IsVariableTemplate, MergeTypeWithPrevious); return true; } return false; |