r187768 - Moved diagnosis of forward declarations of variable templates from Parser to Sema.

Larisse Voufo lvoufo at google.com
Mon Aug 5 20:43:07 PDT 2013


Author: lvoufo
Date: Mon Aug  5 22:43:07 2013
New Revision: 187768

URL: http://llvm.org/viewvc/llvm-project?rev=187768&view=rev
Log:
Moved diagnosis of forward declarations of variable templates from Parser to Sema.

Modified:
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/Driver/crash-report.c

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Aug  5 22:43:07 2013
@@ -2560,7 +2560,7 @@ class VarTemplatePartialSpecializationDe
   VarTemplatePartialSpecializationDecl()
       : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization),
         TemplateParams(0), ArgsAsWritten(0), NumArgsAsWritten(0),
-        SequenceNumber(0), InstantiatedFromMember(0, false) {}
+        SequenceNumber(SequenceNumber), InstantiatedFromMember(0, false) {}
 
 public:
   static VarTemplatePartialSpecializationDecl *

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Aug  5 22:43:07 2013
@@ -606,10 +606,6 @@ def err_explicit_instantiation_enum : Er
     "enumerations cannot be explicitly instantiated">;
 def err_expected_template_parameter : Error<"expected template parameter">;
 
-def err_forward_var_nested_name_specifier : Error<
-  "forward declaration of variable template%select{| partial specialization}0 cannot "
-  "have a nested name specifier">;
-
 def err_missing_dependent_template_keyword : Error<
   "use 'template' keyword to treat '%0' as a dependent template name">;
 def warn_missing_dependent_template_keyword : ExtWarn<

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug  5 22:43:07 2013
@@ -4398,6 +4398,9 @@ def ext_standalone_specifier : ExtWarn<"
 def err_standalone_class_nested_name_specifier : Error<
   "forward declaration of %select{class|struct|interface|union|enum}0 cannot "
   "have a nested name specifier">;
+def err_forward_var_nested_name_specifier : Error<
+  "forward declaration of variable template%select{| partial specialization}0 cannot "
+  "have a nested name specifier">;
 def err_typecheck_sclass_func : Error<"illegal storage class on function">;
 def err_static_block_func : Error<
   "function declared in block scope cannot have 'static' storage class">;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Aug  5 22:43:07 2013
@@ -1461,6 +1461,7 @@ public:
                                     LookupResult &Previous);
   NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
                                   LookupResult &Previous, bool &Redeclaration);
+  bool HandleVariableRedeclaration(Decl *D, CXXScopeSpec &SS);
   NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
                                      TypeSourceInfo *TInfo,
                                      LookupResult &Previous,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Aug  5 22:43:07 2013
@@ -1801,21 +1801,11 @@ Decl *Parser::ParseDeclarationAfterDecla
     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

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug  5 22:43:07 2013
@@ -4770,6 +4770,21 @@ static bool shouldConsiderLinkage(const
   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,
       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,
           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))

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Aug  5 22:43:07 2013
@@ -3461,7 +3461,6 @@ void Sema::InstantiateVariableDefinition
                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() &&

Modified: cfe/trunk/test/Driver/crash-report.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/crash-report.c?rev=187768&r1=187767&r2=187768&view=diff
==============================================================================
--- cfe/trunk/test/Driver/crash-report.c (original)
+++ cfe/trunk/test/Driver/crash-report.c Mon Aug  5 22:43:07 2013
@@ -14,9 +14,6 @@
 
 // RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH=1 %clang -fsyntax-only -x c /dev/null 2>&1 | FileCheck %s
 
-// FIXME: Investigating. "fatal error: file 'nul' modified since it was first processed"
-// XFAIL: mingw32
-
 #pragma clang __debug parser_crash
 // CHECK: Preprocessed source(s) and associated run script(s) are located at:
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.c





More information about the cfe-commits mailing list