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

an asm label.

llvm-svn: 184069
This commit is contained in:
Richard Smith 2013-06-17 01:34:01 +00:00
parent 37ba45a3c5
commit f2c9afceef
4 changed files with 19 additions and 14 deletions

View File

@ -2771,13 +2771,6 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
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;

View File

@ -4727,6 +4727,17 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
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, Declarator &D, DeclContext *DC,
// 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, Declarator &D, DeclContext *DC,
D.setInvalidType();
}
}
if (getLangOpts().OpenCL) {
// Set up the special work-group-local storage class for variables in the
// OpenCL __local address space.

View File

@ -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}}

View File

@ -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@-2 {{'register' storage class specifier is deprecated}}
#endif
register int m asm("rbx"); // no-warning
int k = to_int(n); // no-warning
bool b;