r229447 - Sema: diagnose use of unscoped deprecated prior to C++14

Saleem Abdulrasool compnerd at compnerd.org
Mon Feb 16 14:27:02 PST 2015


Author: compnerd
Date: Mon Feb 16 16:27:01 2015
New Revision: 229447

URL: http://llvm.org/viewvc/llvm-project?rev=229447&view=rev
Log:
Sema: diagnose use of unscoped deprecated prior to C++14

The deprecated attribute was adopted as part of the C++14, however, there is a
GNU version available in C++11.  When using C++ earlier than C++14, diagnose the
use of the attribute without the GNU scope, but only when using the generalised
attribute syntax.

Added:
    cfe/trunk/test/SemaCXX/generalized-deprecated.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Parser/cxx0x-attributes.cpp
    cfe/trunk/test/SemaCXX/for-range-examples.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=229447&r1=229446&r2=229447&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Feb 16 16:27:01 2015
@@ -7233,6 +7233,10 @@ def err_asm_naked_this_ref : Error<
 def err_asm_naked_parm_ref : Error<
   "parameter references not allowed in naked functions">;
 
+def ext_use_of_attribute_is_a_cxx14_extension
+    : ExtWarn<"use of the %0 attribute is a C++14 extension">,
+      InGroup<CXX14>;
+
 // OpenCL warnings and errors.
 def err_invalid_astype_of_different_size : Error<
   "invalid reinterpretation: sizes of %0 and %1 must match">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=229447&r1=229446&r2=229447&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Feb 16 16:27:01 2015
@@ -4254,6 +4254,13 @@ static void handleDeprecatedAttr(Sema &S
       return;
     }
   }
+
+  if (!S.getLangOpts().CPlusPlus14)
+    if (Attr.isCXX11Attribute() &&
+        !(Attr.hasScope() && Attr.getScopeName()->isStr("gnu")))
+      S.Diag(Attr.getLoc(), diag::ext_use_of_attribute_is_a_cxx14_extension)
+          << Attr.getName()->getNameStart();
+
   handleAttrWithMessage<DeprecatedAttr>(S, D, Attr);
 }
 

Modified: cfe/trunk/test/Parser/cxx0x-attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=229447&r1=229446&r2=229447&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-attributes.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-attributes.cpp Mon Feb 16 16:27:01 2015
@@ -288,6 +288,7 @@ namespace arguments {
   void f[[gnu::format(printf, 1, 2)]](const char*, ...);
   void g() [[unknown::foo(ignore arguments for unknown attributes, even with symbols!)]]; // expected-warning {{unknown attribute 'foo' ignored}}
   [[deprecated("with argument")]] int i;
+  // expected-warning at -1 {{use of the deprecated attribute is a C++14 extension}}
 }
 
 // Forbid attributes on decl specifiers.
@@ -330,8 +331,12 @@ namespace GccASan {
 
 namespace {
   [[deprecated]] void bar();
+  // expected-warning at -1 {{use of the deprecated attribute is a C++14 extension}}
   [[deprecated("hello")]] void baz();
-  [[deprecated()]] void foo(); // expected-error {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}}
+  // expected-warning at -1 {{use of the deprecated attribute is a C++14 extension}}
+  [[deprecated()]] void foo();
+  // expected-error at -1 {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}}
+  // expected-warning at -2 {{use of the deprecated attribute is a C++14 extension}}
   [[gnu::deprecated()]] void quux();
 }
 

Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=229447&r1=229446&r2=229447&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/for-range-examples.cpp (original)
+++ cfe/trunk/test/SemaCXX/for-range-examples.cpp Mon Feb 16 16:27:01 2015
@@ -226,7 +226,7 @@ namespace test7 {
     // we check the alignment attribute before we perform the auto
     // deduction.
     for (d alignas(1) : arr) {} // expected-error {{requires type for loop variable}}
-    for (e [[deprecated]] : arr) { e = 0; } // expected-warning {{deprecated}} expected-note {{here}} expected-error {{requires type for loop variable}}
+    for (e [[deprecated]] : arr) { e = 0; } // expected-warning{{use of the deprecated attribute is a C++14 extension}} expected-warning {{deprecated}} expected-note {{here}} expected-error {{requires type for loop variable}}
   }
 }
 

Added: cfe/trunk/test/SemaCXX/generalized-deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/generalized-deprecated.cpp?rev=229447&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/generalized-deprecated.cpp (added)
+++ cfe/trunk/test/SemaCXX/generalized-deprecated.cpp Mon Feb 16 16:27:01 2015
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -Wno-deprecated %s
+
+// NOTE: use -Wno-deprecated to avoid cluttering the output with deprecated
+// warnings
+
+[[deprecated("1")]] int function_1();
+// expected-warning at -1 {{use of the deprecated attribute is a C++14 extension}}
+
+[[gnu::deprecated("3")]] int function_3();
+
+int __attribute__ (( deprecated("2") )) function_2();
+
+__declspec(deprecated("4")) int function_4();
+





More information about the cfe-commits mailing list