+2019-11-15 Joseph Myers <joseph@codesourcery.com>
+
+ * c-decl.c (std_attribute_table): Add maybe_unused.
+
2019-11-15 Joseph Myers <joseph@codesourcery.com>
* c-decl.c (std_attribute_table): Add fallthrough.
handle_deprecated_attribute, NULL },
{ "fallthrough", 0, 0, false, false, false, false,
handle_fallthrough_attribute, NULL },
+ { "maybe_unused", 0, 0, false, false, false, false,
+ handle_unused_attribute, NULL },
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};
+2019-11-15 Joseph Myers <joseph@codesourcery.com>
+
+ * gcc.dg/c2x-attr-maybe_unused-1.c,
+ gcc.dg/c2x-attr-maybe_unused-2.c,
+ gcc.dg/c2x-attr-maybe_unused-3.c: New tests.
+
2019-11-15 Matthew Malcomson <matthew.malcomson@arm.com>
* gcc.dg/rtl/aarch64/rtl-handle-column-numbers.c: New test.
--- /dev/null
+/* Test C2x maybe_unused attribute: valid uses. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors -Wall -Wextra -Wunused" } */
+
+[[maybe_unused]] static void f1 (void) {}
+
+[[__maybe_unused__]] const int c1 = 1;
+static int c2 [[maybe_unused]] = 2;
+
+int
+g ([[maybe_unused]] int x, int y)
+{
+ [[maybe_unused]] typedef float F;
+ [[maybe_unused]] int a;
+ int b [[__maybe_unused__]];
+ int c [[maybe_unused]];
+ c = y;
+ return y;
+}
+
+struct [[maybe_unused]] s { double d; };
+
+struct s2 { [[__maybe_unused__]] int a; int b [[maybe_unused]]; } x; /* { dg-warning "attribute ignored" } */
+
+enum e { E1 [[maybe_unused]] };
+
+union [[maybe_unused]] u { int x; };
+
+enum [[maybe_unused]] eu { E2 };
+
+union u2 { [[maybe_unused]] int a; int b [[maybe_unused]]; } y; /* { dg-warning "attribute ignored" } */
--- /dev/null
+/* Test C2x maybe_unused attribute: invalid contexts. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+/* This attribute is not valid in most cases on types other than their
+ definitions, or on statements, or as an attribute-declaration. */
+
+[[maybe_unused]]; /* { dg-warning "ignored" } */
+
+int [[maybe_unused]] var; /* { dg-warning "ignored" } */
+/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+
+int array_with_dep_type[2] [[maybe_unused]]; /* { dg-warning "ignored" } */
+/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+
+void fn_with_dep_type () [[maybe_unused]]; /* { dg-warning "ignored" } */
+/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+
+void
+f (void)
+{
+ int a;
+ [[maybe_unused]]; /* { dg-warning "ignored" } */
+ [[maybe_unused]] a = 1; /* { dg-warning "ignored" } */
+}
--- /dev/null
+/* Test C2x maybe_unused attribute: invalid syntax. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+[[maybe_unused()]] int a; /* { dg-error "does not take any arguments" } */
+
+[[maybe_unused(0)]] int b; /* { dg-error "does not take any arguments|expected" } */
+
+[[maybe_unused("", 123)]] int c; /* { dg-error "does not take any arguments|expected" } */
+
+[[maybe_unused("")]] int d; /* { dg-error "does not take any arguments|expected" } */