diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 30402411178d..d0d44cbc5ebc 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 0ad59b2c153a..6b9f0aab6c91 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 36dd1c80e780..972bb0fe04e4 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 77b81a523833..cb33c0c242e7 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; };