Author: Aaron Ballman Date: 2022-09-13T09:33:20-04:00 New Revision: 0f28cf416d00a0fa0cb6cf572dd7ebbc19529190
URL: https://github.com/llvm/llvm-project/commit/0f28cf416d00a0fa0cb6cf572dd7ebbc19529190 DIFF: https://github.com/llvm/llvm-project/commit/0f28cf416d00a0fa0cb6cf572dd7ebbc19529190.diff LOG: Correct the __has_c_attribute value for maybe_unused The original proposal was adopted in Apr 2019, but was subsequently updated by WG14 N2662 in June 2021. We already supported the attribute on a label and it behaved as expected, but we 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-maybe_unused.c clang/www/c_status.html Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d0d44cbc5ebcd..9bc96f4dc1e96 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -210,6 +210,9 @@ C Language Changes in Clang C2x Feature Support ------------------- +- Implemented `WG14 N2662 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2662.pdf>`_, + so the [[maybe_unused]] attribute may be applied to a label to silence an + ``-Wunused-label`` warning. C++ Language Changes in Clang ----------------------------- diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 6b9f0aab6c91d..48c7791ebe330 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2893,7 +2893,7 @@ def ObjCRequiresPropertyDefs : InheritableAttr { def Unused : InheritableAttr { let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">, - C2x<"", "maybe_unused", 201904>]; + C2x<"", "maybe_unused", 202106>]; let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label, Field, ObjCMethod, FunctionLike]>; let Documentation = [WarnMaybeUnusedDocs]; diff --git a/clang/test/Preprocessor/has_c_attribute.c b/clang/test/Preprocessor/has_c_attribute.c index 972bb0fe04e4f..401daa72b85b1 100644 --- a/clang/test/Preprocessor/has_c_attribute.c +++ b/clang/test/Preprocessor/has_c_attribute.c @@ -24,7 +24,7 @@ C2x(clang::annotate) // CHECK: deprecated: 201904L C2x(deprecated) -// CHECK: maybe_unused: 201904L +// CHECK: maybe_unused: 202106L C2x(maybe_unused) // CHECK: __gnu__::warn_unused_result: 202003L diff --git a/clang/test/Sema/c2x-maybe_unused.c b/clang/test/Sema/c2x-maybe_unused.c index 82b9634fc9f39..f531521227d7f 100644 --- a/clang/test/Sema/c2x-maybe_unused.c +++ b/clang/test/Sema/c2x-maybe_unused.c @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s +// This is the latest version of maybe_unused that we support. +_Static_assert(__has_c_attribute(maybe_unused) == 202106L); + struct [[maybe_unused]] S1 { // ok int a [[maybe_unused]]; }; @@ -33,3 +36,10 @@ void f2(void); void f2(void) { } +void label(void) { + [[maybe_unused]] label: + ; + + other_label: // expected-warning {{unused label 'other_label'}} + ; +} diff --git a/clang/www/c_status.html b/clang/www/c_status.html index 7d97a6bc1f13f..381a05d07eda6 100644 --- a/clang/www/c_status.html +++ b/clang/www/c_status.html @@ -851,7 +851,7 @@ <h2 id="c2x">C2x implementation status</h2> <tr> <td>[[maybe_unused]] for labels</td> <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2662.pdf">N2662</a></td> - <td class="none" align="center">No</td> + <td class="unreleased" align="center">Clang 16</td> </tr> <tr> <td>Zeros compare equal</td> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits