[clang] 1b19df1 - Correct the __has_c_attribute value for nodiscard

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 13 05:13:13 PDT 2022


Author: Aaron Ballman
Date: 2022-09-13T08:13:01-04:00
New Revision: 1b19df12b84a7045f75e34009a3a7ff44f599375

URL: https://github.com/llvm/llvm-project/commit/1b19df12b84a7045f75e34009a3a7ff44f599375
DIFF: https://github.com/llvm/llvm-project/commit/1b19df12b84a7045f75e34009a3a7ff44f599375.diff

LOG: Correct the __has_c_attribute value for nodiscard

The original proposal was adopted in Apr 2019 and so the previous value
was 201904L. However, a subsequent proposal (N2448) was adopted to add
an optional message argument to the attribute. We already support that
functionality, but had not bumped the feature test value.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/Basic/Attr.td
    clang/test/Preprocessor/has_c_attribute.c
    clang/test/Sema/c2x-nodiscard.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 30402411178d4..d0d44cbc5ebcd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -183,6 +183,11 @@ Attribute Changes in Clang
 - Introduced a new function attribute ``__attribute__((nouwtable))`` to suppress
   LLVM IR ``uwtable`` function attribute.
 
+- Updated the value returned by ``__has_c_attribute(nodiscard)`` to ``202003L``
+  based on the final date specified by the C2x committee draft. We already
+  supported the ability to specify a message in the attribute, so there were no
+  changes to the attribute behavior.
+
 Windows Support
 ---------------
 - For the MinGW driver, added the options ``-mguard=none``, ``-mguard=cf`` and

diff  --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 0ad59b2c153ae..6b9f0aab6c91d 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2987,7 +2987,7 @@ def WarnUnused : InheritableAttr {
 
 def WarnUnusedResult : InheritableAttr {
   let Spellings = [CXX11<"", "nodiscard", 201907>,
-                   C2x<"", "nodiscard", 201904>,
+                   C2x<"", "nodiscard", 202003>,
                    CXX11<"clang", "warn_unused_result">,
                    GCC<"warn_unused_result">];
   let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike, TypedefName]>;

diff  --git a/clang/test/Preprocessor/has_c_attribute.c b/clang/test/Preprocessor/has_c_attribute.c
index 36dd1c80e7802..972bb0fe04e4f 100644
--- a/clang/test/Preprocessor/has_c_attribute.c
+++ b/clang/test/Preprocessor/has_c_attribute.c
@@ -6,7 +6,7 @@
 // CHECK: fallthrough: 201904L
 C2x(fallthrough)
 
-// CHECK: __nodiscard__: 201904L
+// CHECK: __nodiscard__: 202003L
 C2x(__nodiscard__)
 
 // CHECK: selectany: 0
@@ -27,10 +27,10 @@ C2x(deprecated)
 // CHECK: maybe_unused: 201904L
 C2x(maybe_unused)
 
-// CHECK: __gnu__::warn_unused_result: 201904L
+// CHECK: __gnu__::warn_unused_result: 202003L
 C2x(__gnu__::warn_unused_result)
 
-// CHECK: gnu::__warn_unused_result__: 201904L
+// CHECK: gnu::__warn_unused_result__: 202003L
 C2x(gnu::__warn_unused_result__)
 
 // Test that macro expansion of the builtin argument works.

diff  --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c
index 77b81a523833c..cb33c0c242e7d 100644
--- a/clang/test/Sema/c2x-nodiscard.c
+++ b/clang/test/Sema/c2x-nodiscard.c
@@ -1,12 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s
 
+// This is the latest version of nodiscard that we support.
+_Static_assert(__has_c_attribute(nodiscard) == 202003L);
+
 struct [[nodiscard]] S1 { // ok
   int i;
 };
 struct [[nodiscard, nodiscard]] S2 { // ok
   int i;
 };
-struct [[nodiscard("Wrong")]] S3 { // FIXME: may need an extension warning.
+struct [[nodiscard("Wrong")]] S3 {
   int i;
 };
 


        


More information about the cfe-commits mailing list