]> granicus.if.org Git - clang/commitdiff
Suppress the c++11 -Wdeprecated warning for 'register' if it is expanded from a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 14 Jun 2013 21:05:24 +0000 (21:05 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 14 Jun 2013 21:05:24 +0000 (21:05 +0000)
macro defined in a system header. glibc uses it in macros, apparently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184005 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
test/SemaCXX/Inputs/register.h [new file with mode: 0644]
test/SemaCXX/deprecated.cpp

index 8d96d6e6ccdf3d9a58f6460d98954ccd89524150..70a7ea58f450a33c5e16d22a4fff802b245add2f 100644 (file)
@@ -2771,7 +2771,11 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
                                            PrevSpec, DiagID);
       break;
     case tok::kw_register:
-      if (getLangOpts().CPlusPlus11)
+      // 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,
diff --git a/test/SemaCXX/Inputs/register.h b/test/SemaCXX/Inputs/register.h
new file mode 100644 (file)
index 0000000..3c412ee
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma GCC system_header
+#pragma once
+
+inline void f() { register int k; }
+#define to_int(x) ({ register int n = (x); n; })
index 5a5cd2f8323193fc1b165b6b79f6b6922e728cc2..75ec0bc4196319b4223a2b1fcd8cd430d3500be4 100644 (file)
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
 // RUN: %clang_cc1 -std=c++1y %s -Wdeprecated -verify
 
+#include "Inputs/register.h"
+
 void f() throw();
 void g() throw(int);
 void h() throw(...);
@@ -17,6 +19,8 @@ void stuff() {
   // expected-warning@-2 {{'register' storage class specifier is deprecated}}
 #endif
 
+  int k = to_int(n); // no-warning
+
   bool b;
   ++b; // expected-warning {{incrementing expression of type bool is deprecated}}