r317140 - Fix missing -Wregister warning when 'register' is applied to a function parameter.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 1 16:38:37 PDT 2017
Author: rsmith
Date: Wed Nov 1 16:38:37 2017
New Revision: 317140
URL: http://llvm.org/viewvc/llvm-project?rev=317140&view=rev
Log:
Fix missing -Wregister warning when 'register' is applied to a function parameter.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp
cfe/trunk/test/SemaCXX/deprecated.cpp
cfe/trunk/test/SemaCXX/varargs.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=317140&r1=317139&r2=317140&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Nov 1 16:38:37 2017
@@ -11718,6 +11718,14 @@ Decl *Sema::ActOnParamDeclarator(Scope *
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;
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp?rev=317140&r1=317139&r2=317140&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp Wed Nov 1 16:38:37 2017
@@ -39,6 +39,7 @@ struct S {
void foo(auto int ap, register int rp) {
#if __cplusplus >= 201103L // C++11 or later
// expected-warning at -2 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
+// expected-warning at -3 {{'register' storage class specifier is deprecated}}
#endif
auto int abo;
#if __cplusplus >= 201103L // C++11 or later
Modified: cfe/trunk/test/SemaCXX/deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/deprecated.cpp?rev=317140&r1=317139&r2=317140&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/deprecated.cpp Wed Nov 1 16:38:37 2017
@@ -20,7 +20,12 @@ void i() throw(...);
// expected-warning at -8 {{dynamic exception specifications are deprecated}} expected-note at -8 {{use 'noexcept(false)' instead}}
#endif
-void stuff() {
+void stuff(register int q) {
+#if __cplusplus > 201402L
+ // expected-error at -2 {{ISO C++17 does not allow 'register' storage class specifier}}
+#elif __cplusplus >= 201103L && !defined(NO_DEPRECATED_FLAGS)
+ // expected-warning at -4 {{'register' storage class specifier is deprecated}}
+#endif
register int n;
#if __cplusplus > 201402L
// expected-error at -2 {{ISO C++17 does not allow 'register' storage class specifier}}
Modified: cfe/trunk/test/SemaCXX/varargs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/varargs.cpp?rev=317140&r1=317139&r2=317140&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/varargs.cpp (original)
+++ cfe/trunk/test/SemaCXX/varargs.cpp Wed Nov 1 16:38:37 2017
@@ -8,7 +8,7 @@ void f(const string& s, ...) { // expec
__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++
}
More information about the cfe-commits
mailing list