Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / dcl.dcl / dcl.attr / dcl.attr.unused / p3.cpp
blob5f715a1ec21d339a10fafdbdd0b645906f4526d7
1 // RUN: %clang_cc1 -fsyntax-only -Wunused -Wused-but-marked-unused -std=c++17 -Wc++17-extensions -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -Wunused -Wused-but-marked-unused -std=c++11 -Wc++17-extensions -verify -DEXT %s
4 static_assert(__has_cpp_attribute(maybe_unused) == 201603, "");
6 struct [[maybe_unused]] S {};
8 enum E1 {
9 EnumVal [[maybe_unused]],
10 UsedEnumVal,
13 void f() {
14 int x; // expected-warning {{unused variable}}
15 typedef int I; // expected-warning {{unused typedef 'I'}}
16 E1 e;
17 switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not handled in switch}}
20 // Should not warn about these due to not being used.
21 [[maybe_unused]] int y;
22 typedef int maybe_unused_int [[maybe_unused]];
24 // Should not warn about these uses.
25 S s;
26 maybe_unused_int test;
27 y = 12;
28 switch (e) {
29 case UsedEnumVal:
30 break;
34 #ifdef EXT
35 // expected-warning@6 {{use of the 'maybe_unused' attribute is a C++17 extension}}
36 // expected-warning@9 {{use of the 'maybe_unused' attribute is a C++17 extension}}
37 // expected-warning@9 {{attributes on an enumerator declaration are a C++17 extension}}
38 // expected-warning@21 {{use of the 'maybe_unused' attribute is a C++17 extension}}
39 // expected-warning@22 {{use of the 'maybe_unused' attribute is a C++17 extension}}
40 #endif