r184069 - C++11: don't warn about the deprecated 'register' keyword if it's combined with

Richard Smith richard-llvm at metafoo.co.uk
Sun Jun 16 18:34:01 PDT 2013


Author: rsmith
Date: Sun Jun 16 20:34:01 2013
New Revision: 184069

URL: http://llvm.org/viewvc/llvm-project?rev=184069&view=rev
Log:
C++11: don't warn about the deprecated 'register' keyword if it's combined with
an asm label.

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/class/class.friend/p6.cpp
    cfe/trunk/test/SemaCXX/deprecated.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=184069&r1=184068&r2=184069&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Jun 16 20:34:01 2013
@@ -2771,13 +2771,6 @@ void Parser::ParseDeclarationSpecifiers(
                                            PrevSpec, DiagID);
       break;
     case tok::kw_register:
-      // In C++11, the 'register' storage class specifier is deprecated.
-      // Suppress the warning in system macros, it's used in macros in some
-      // popular C system headers, such as in glibc's htonl() macro.
-      if (getLangOpts().CPlusPlus11 &&
-          !PP.getSourceManager().isInSystemMacro(Tok.getLocation()))
-        Diag(Tok, diag::warn_deprecated_register)
-          << FixItHint::CreateRemoval(Tok.getLocation());
       isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_register, Loc,
                                          PrevSpec, DiagID);
       break;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=184069&r1=184068&r2=184069&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Jun 16 20:34:01 2013
@@ -4727,6 +4727,17 @@ Sema::ActOnVariableDeclarator(Scope *S,
     SC = SC_None;
   }
 
+  if (getLangOpts().CPlusPlus11 && SCSpec == DeclSpec::SCS_register &&
+      !D.getAsmLabel() && !getSourceManager().isInSystemMacro(
+                              D.getDeclSpec().getStorageClassSpecLoc())) {
+    // In C++11, the 'register' storage class specifier is deprecated.
+    // Suppress the warning in system macros, it's used in macros in some
+    // popular C system headers, such as in glibc's htonl() macro.
+    Diag(D.getDeclSpec().getStorageClassSpecLoc(),
+         diag::warn_deprecated_register)
+      << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc());
+  }
+
   IdentifierInfo *II = Name.getAsIdentifierInfo();
   if (!II) {
     Diag(D.getIdentifierLoc(), diag::err_bad_variable_name)
@@ -4740,7 +4751,6 @@ Sema::ActOnVariableDeclarator(Scope *S,
     // C99 6.9p2: The storage-class specifiers auto and register shall not
     // appear in the declaration specifiers in an external declaration.
     if (SC == SC_Auto || SC == SC_Register) {
-
       // If this is a register variable with an asm label specified, then this
       // is a GNU extension.
       if (SC == SC_Register && D.getAsmLabel())
@@ -4750,7 +4760,7 @@ Sema::ActOnVariableDeclarator(Scope *S,
       D.setInvalidType();
     }
   }
-  
+
   if (getLangOpts().OpenCL) {
     // Set up the special work-group-local storage class for variables in the
     // OpenCL __local address space.

Modified: cfe/trunk/test/CXX/class/class.friend/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.friend/p6.cpp?rev=184069&r1=184068&r2=184069&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.friend/p6.cpp (original)
+++ cfe/trunk/test/CXX/class/class.friend/p6.cpp Sun Jun 16 20:34:01 2013
@@ -7,7 +7,7 @@ class A {
 #if __cplusplus < 201103L
   friend register class E; // expected-error {{'register' is invalid in friend declarations}}
 #else
-  friend register class E; // expected-error {{'register' is invalid in friend declarations}} expected-warning {{deprecated}}
+  friend register class E; // expected-error {{'register' is invalid in friend declarations}}
 #endif
   friend mutable class F; // expected-error {{'mutable' is invalid in friend declarations}}
   friend typedef class G; // expected-error {{'typedef' is invalid in friend declarations}}

Modified: cfe/trunk/test/SemaCXX/deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/deprecated.cpp?rev=184069&r1=184068&r2=184069&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/deprecated.cpp Sun Jun 16 20:34:01 2013
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -std=c++98 %s -Wdeprecated -verify
-// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
-// RUN: %clang_cc1 -std=c++1y %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++98 %s -Wdeprecated -verify -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++1y %s -Wdeprecated -verify -triple x86_64-linux-gnu
 
-// RUN: %clang_cc1 -std=c++1y %s -Wdeprecated -verify -Wno-deprecated-register -DNO_DEPRECATED_FLAGS
+// RUN: %clang_cc1 -std=c++1y %s -Wdeprecated -verify -triple x86_64-linux-gnu -Wno-deprecated-register -DNO_DEPRECATED_FLAGS
 
 #include "Inputs/register.h"
 
@@ -21,6 +21,8 @@ void stuff() {
   // expected-warning at -2 {{'register' storage class specifier is deprecated}}
 #endif
 
+  register int m asm("rbx"); // no-warning
+
   int k = to_int(n); // no-warning
 
   bool b;





More information about the cfe-commits mailing list