Fix missing -Wregister warning when 'register' is applied to a function parameter.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Nov 2017 23:38:37 +0000 (23:38 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Nov 2017 23:38:37 +0000 (23:38 +0000)
llvm-svn: 317140

clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp
clang/test/SemaCXX/deprecated.cpp
clang/test/SemaCXX/varargs.cpp

index d68b430..0c00ef7 100644 (file)
@@ -11718,6 +11718,14 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
   StorageClass SC = SC_None;
   if (DS.getStorageClassSpec() == DeclSpec::SCS_register) {
     SC = SC_Register;
+    // In C++11, the 'register' storage class specifier is deprecated.
+    // In C++17, it is not allowed, but we tolerate it as an extension.
+    if (getLangOpts().CPlusPlus11) {
+      Diag(DS.getStorageClassSpecLoc(),
+           getLangOpts().CPlusPlus1z ? diag::ext_register_storage_class
+                                     : diag::warn_deprecated_register)
+        << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
+    }
   } else if (getLangOpts().CPlusPlus &&
              DS.getStorageClassSpec() == DeclSpec::SCS_auto) {
     SC = SC_Auto;
index 0b7a902..1372151 100644 (file)
@@ -39,6 +39,7 @@ struct S {
 void foo(auto int ap, register int rp) {
 #if __cplusplus >= 201103L // C++11 or later
 // expected-warning@-2 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
+// expected-warning@-3 {{'register' storage class specifier is deprecated}}
 #endif
   auto int abo;
 #if __cplusplus >= 201103L // C++11 or later
index a838cda..773085b 100644 (file)
@@ -20,7 +20,12 @@ void i() throw(...);
 // expected-warning@-8 {{dynamic exception specifications are deprecated}} expected-note@-8 {{use 'noexcept(false)' instead}}
 #endif
 
-void stuff() {
+void stuff(register int q) {
+#if __cplusplus > 201402L
+  // expected-error@-2 {{ISO C++17 does not allow 'register' storage class specifier}}
+#elif __cplusplus >= 201103L && !defined(NO_DEPRECATED_FLAGS)
+  // expected-warning@-4 {{'register' storage class specifier is deprecated}}
+#endif
   register int n;
 #if __cplusplus > 201402L
   // expected-error@-2 {{ISO C++17 does not allow 'register' storage class specifier}}
index f9027c2..f2f53dc 100644 (file)
@@ -8,7 +8,7 @@ void f(const string& s, ...) {  // expected-note {{parameter of type 'const stri
   __builtin_va_start(ap, s); // expected-warning {{passing an object of reference type to 'va_start' has undefined behavior}}
 }
 
-void g(register int i, ...) {
+void g(register int i, ...) { // expected-warning 0-1{{deprecated}}
   __builtin_va_start(ap, i); // UB in C, OK in C++
 }