From 6b759f4d3c8bce0fe1f416953ef790c68e7c30b2 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 14 Jun 2013 21:05:24 +0000 Subject: [PATCH] Suppress the c++11 -Wdeprecated warning for 'register' if it is expanded from a 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 | 6 +++++- test/SemaCXX/Inputs/register.h | 5 +++++ test/SemaCXX/deprecated.cpp | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/Inputs/register.h diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 8d96d6e6cc..70a7ea58f4 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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 index 0000000000..3c412eeb12 --- /dev/null +++ b/test/SemaCXX/Inputs/register.h @@ -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; }) diff --git a/test/SemaCXX/deprecated.cpp b/test/SemaCXX/deprecated.cpp index 5a5cd2f832..75ec0bc419 100644 --- a/test/SemaCXX/deprecated.cpp +++ b/test/SemaCXX/deprecated.cpp @@ -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}} -- 2.40.0