Debian Codegraph @

clang/test/Sema/c2x-maybe_unused.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
2
3 // This is the latest version of maybe_unused that we support.
4 _Static_assert(__has_c_attribute(maybe_unused) == 202106L);
5
6 struct [[maybe_unused]] S1 { // ok
7 int a [[maybe_unused]];
8 };
9
10 enum [[maybe_unused]] E1 {
11 EnumVal [[maybe_unused]]
12 };
13
14 [[maybe_unused]] void unused_func([[maybe_unused]] int parm) {
15 typedef int maybe_unused_int [[maybe_unused]];
16 [[maybe_unused]] int I;
17 }
18
19 void f1(void) {
20 int x; // expected-warning {{unused variable}}
21 typedef int I; // expected-warning {{unused typedef 'I'}}
22
23 // Should not warn about these due to not being used.
24 [[maybe_unused]] int y;
25 typedef int maybe_unused_int [[maybe_unused]];
26
27 // Should not warn about these uses.
28 struct S1 s;
29 maybe_unused_int test;
30 y = 12;
31 }
32
33 void f2(void);
34 [[maybe_unused]] void f2(void);
35
36 void f2(void) {
37 }
38
39 void label(void) {
40 [[maybe_unused]] label:
41 ;
42
43 other_label: // expected-warning {{unused label 'other_label'}}
44 ;
45 }