diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 14 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 20 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 |
3 files changed, 20 insertions, 15 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 80fab62f41e..3f15b5b089a 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1801,21 +1801,11 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(), *TemplateInfo.TemplateParams, D); - - // If this is a forward declaration of a variable template or variable - // template partial specialization with nested name specifier, complain. - // FIXME: Move to Sema. - CXXScopeSpec &SS = D.getCXXScopeSpec(); - if (Tok.is(tok::semi) && ThisDecl && SS.isNotEmpty() && - (isa<VarTemplateDecl>(ThisDecl) || - isa<VarTemplatePartialSpecializationDecl>(ThisDecl))) { - Diag(SS.getBeginLoc(), diag::err_forward_var_nested_name_specifier) - << isa<VarTemplatePartialSpecializationDecl>(ThisDecl) - << SS.getRange(); + if (Tok.is(tok::semi) && + Actions.HandleVariableRedeclaration(ThisDecl, D.getCXXScopeSpec())) { SkipUntil(tok::semi, true, true); return 0; } - if (VarTemplateDecl *VT = ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) : 0) // Re-direct this decl to refer to the templated decl so that we can diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 80ac1167ffa..15e6a492725 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4770,6 +4770,21 @@ static bool shouldConsiderLinkage(const FunctionDecl *FD) { llvm_unreachable("Unexpected context"); } +bool Sema::HandleVariableRedeclaration(Decl *D, CXXScopeSpec &SS) { + // If this is a redeclaration of a variable template or a forward + // declaration of a variable template partial specialization + // with nested name specifier, complain. + + if (D && SS.isNotEmpty() && + (isa<VarTemplateDecl>(D) || + isa<VarTemplatePartialSpecializationDecl>(D))) { + Diag(SS.getBeginLoc(), diag::err_forward_var_nested_name_specifier) + << isa<VarTemplatePartialSpecializationDecl>(D) << SS.getRange(); + return true; + } + return false; +} + NamedDecl * Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, @@ -4907,7 +4922,8 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, case SC_OpenCLWorkGroupLocal: llvm_unreachable("OpenCL storage class in c++!"); } - } + } + if (SC == SC_Static && CurContext->isRecord()) { if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) { if (RD->isLocalClass()) @@ -4966,7 +4982,7 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, IsPartialSpecialization = TemplateParams->size() > 0; } else { // if (TemplateParams->size() > 0) - // This is a template declaration. + // This is a template declaration. // Check that we can declare a template here. if (CheckTemplateDeclScope(S, TemplateParams)) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 0ca6611c358..b93fe9a966a 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3461,7 +3461,6 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VarSpec->getTemplateArgsInfo(), InstantiationDependent) && "Only instantiate variable template specializations that are " "not type-dependent"); - (void)InstantiationDependent; // Find the variable initialization that we'll be substituting. assert(VarSpec->getSpecializedTemplate() && |

