r178795 - Don't patch the storage class of static data members.

Rafael Espindola rafael.espindola at gmail.com
Thu Apr 4 14:21:25 PDT 2013


Author: rafael
Date: Thu Apr  4 16:21:25 2013
New Revision: 178795

URL: http://llvm.org/viewvc/llvm-project?rev=178795&view=rev
Log:
Don't patch the storage class of static data members.

This removes a bit of patching that survived r178663. Without it we can produce
better a better error message for

const int a = 5;
static const int a;

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/linkage2.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=178795&r1=178794&r2=178795&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr  4 16:21:25 2013
@@ -2896,9 +2896,10 @@ void Sema::MergeVarDecl(VarDecl *New, Lo
   if (New->isInvalidDecl())
     return;
 
-  // C99 6.2.2p4: Check if we have a static decl followed by a non-static.
+  // [dcl.stc]p8: Check if we have a non-static decl followed by a static.
   if (New->getStorageClass() == SC_Static &&
-      (Old->getStorageClass() == SC_None || Old->hasExternalStorage())) {
+      !New->isStaticDataMember() &&
+      isExternalLinkage(Old->getLinkage())) {
     Diag(New->getLocation(), diag::err_static_non_static) << New->getDeclName();
     Diag(Old->getLocation(), diag::note_previous_definition);
     return New->setInvalidDecl();
@@ -2915,6 +2916,7 @@ void Sema::MergeVarDecl(VarDecl *New, Lo
   if (New->hasExternalStorage() && Old->hasLinkage())
     /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
+           !New->isStaticDataMember() &&
            Old->getCanonicalDecl()->getStorageClass() == SC_Static) {
     Diag(New->getLocation(), diag::err_non_static_static) << New->getDeclName();
     Diag(Old->getLocation(), diag::note_previous_definition);
@@ -4781,8 +4783,7 @@ Sema::ActOnVariableDeclarator(Scope *S,
         Diag(D.getDeclSpec().getStorageClassSpecLoc(),
              diag::err_static_out_of_line)
           << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc());
-      } else if (SC == SC_None)
-        SC = SC_Static;
+      }
     }
     if (SC == SC_Static && CurContext->isRecord()) {
       if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {

Modified: cfe/trunk/test/SemaCXX/linkage2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage2.cpp?rev=178795&r1=178794&r2=178795&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/linkage2.cpp (original)
+++ cfe/trunk/test/SemaCXX/linkage2.cpp Thu Apr  4 16:21:25 2013
@@ -147,3 +147,8 @@ namespace test14 {
     static void a(void) {} // expected-error {{static declaration of 'a' follows non-static declaration}}
   }
 }
+
+namespace test15 {
+  const int a = 5; // expected-note {{previous definition is here}}
+  static const int a; // expected-error {{redefinition of 'a'}}
+}





More information about the cfe-commits mailing list