| 1 |
/* Test C23 deprecated attribute: valid uses. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
[[nodiscard]] int c1 (void); /* { dg-message "declared here" } */ |
| 6 |
[[__nodiscard__ ("some reason")]] int c2 (void); /* { dg-message "declared here" } */ |
| 7 |
|
| 8 |
struct [[nodiscard ("struct reason")]] s1 { int a; }; |
| 9 |
struct [[__nodiscard__]] s2 { long b; }; |
| 10 |
struct s1 cs1 (void); /* { dg-message "declared here" } */ |
| 11 |
struct s2 cs2 (void); /* { dg-message "declared here" } */ |
| 12 |
typedef struct s2 s2t; |
| 13 |
s2t cs3 (void); /* { dg-message "declared here" } */ |
| 14 |
|
| 15 |
union [[nodiscard]] u1 { int a; long b; }; |
| 16 |
union [[nodiscard ("union reason")]] u2 { short c; float d; }; |
| 17 |
union u1 cu1 (void); /* { dg-message "declared here" } */ |
| 18 |
union u2 cu2 (void); /* { dg-message "declared here" } */ |
| 19 |
|
| 20 |
enum [[nodiscard]] e1 { E1 }; |
| 21 |
enum [[nodiscard ("enum reason")]] e2 { E2 }; |
| 22 |
enum e1 ce1 (void); /* { dg-message "declared here" } */ |
| 23 |
enum e2 ce2 (void); /* { dg-message "declared here" } */ |
| 24 |
enum e1 ce1a (void); |
| 25 |
int i; |
| 26 |
|
| 27 |
[[nodiscard]] void v (void); /* { dg-warning "void return type" } */ |
| 28 |
|
| 29 |
int ok (void); |
| 30 |
|
| 31 |
void |
| 32 |
f (void) |
| 33 |
{ |
| 34 |
c1 (); /* { dg-warning "ignoring return value" } */ |
| 35 |
c2 (); /* { dg-warning "some reason" } */ |
| 36 |
cs1 (); /* { dg-warning "struct reason" } */ |
| 37 |
cs2 (); /* { dg-warning "ignoring return value of type" } */ |
| 38 |
cs3 (); /* { dg-warning "ignoring return value of type" } */ |
| 39 |
cu1 (); /* { dg-warning "ignoring return value of type" } */ |
| 40 |
cu2 (); /* { dg-warning "union reason" } */ |
| 41 |
ce1 (); /* { dg-warning "ignoring return value of type" } */ |
| 42 |
ce2 (); /* { dg-warning "enum reason" } */ |
| 43 |
ok (); |
| 44 |
c1 (), ok (); /* { dg-warning "ignoring return value" } */ |
| 45 |
cs1 (), ok (); /* { dg-warning "struct reason" } */ |
| 46 |
ok (), cu1 (); /* { dg-warning "ignoring return value" } */ |
| 47 |
ok (), (ok (), (ok (), ce2 ())); /* { dg-warning "enum reason" } */ |
| 48 |
(ok (), cu1 ()), ok (); /* { dg-warning "ignoring return value" } */ |
| 49 |
v (); |
| 50 |
(i ? ce1 : ce1a) (); /* { dg-warning "ignoring return value of type" } */ |
| 51 |
(void) c1 (); |
| 52 |
(void) c2 (); |
| 53 |
(void) cs1 (); |
| 54 |
(void) cs2 (); |
| 55 |
(void) cs3 (); |
| 56 |
(void) cu1 (); |
| 57 |
(void) cu2 (); |
| 58 |
(void) ce1 (); |
| 59 |
(void) ce2 (); |
| 60 |
(void) (ok (), cu1 ()); |
| 61 |
(void) (i ? ce1 : ce1a) (); |
| 62 |
} |