1 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code -Wno-strict-prototypes
5 double sqrt(double X
); // implicitly const because of no -fmath-errno!
7 void bar(volatile int *VP
, int *P
, int A
,
8 _Complex
double C
, volatile _Complex
double VC
) {
10 VP
< P
; // expected-warning {{relational comparison result unused}}
12 (void)foo(1,2); // no warning.
14 A
< foo(1, 2); // expected-warning {{relational comparison result unused}}
16 foo(1,2)+foo(4,3); // expected-warning {{expression result unused}}
19 *P
; // expected-warning {{expression result unused}}
21 P
[4]; // expected-warning {{expression result unused}}
24 __real__ C
; // expected-warning {{expression result unused}}
27 // We know this can't change errno because of no -fmath-errno.
28 sqrt(A
); // expected-warning {{ignoring return value of function declared with const attribute}}
37 // This shouldn't warn: the expr at the end of the stmtexpr really is used.
38 int stmt_expr(int x
, int y
) {
39 return ({int _a
= x
, _b
= y
; _a
> _b
? _a
: _b
; });
42 void nowarn(unsigned char* a
, unsigned char* b
)
57 b
< 1; // expected-warning{{relational comparison result unused}}
59 b
< 2; // expected-warning{{relational comparison result unused}}
62 b
< 3; // expected-warning{{relational comparison result unused}}
65 b
< 4; // expected-warning{{relational comparison result unused}}
69 b
< 5; // expected-warning{{relational comparison result unused}}
71 for (b
< 1;;) {} // expected-warning{{relational comparison result unused}}
73 for (;;b
< 1) {} // expected-warning{{relational comparison result unused}}
77 int t5f(void) __attribute__((warn_unused_result
));
79 t5f(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}}
83 int fn1(void) __attribute__ ((warn_unused_result
));
84 int fn2() __attribute__ ((pure
));
85 int fn3() __attribute__ ((__const
));
88 if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0) // no warnings
91 fn1(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}}
92 fn2(92, 21); // expected-warning {{ignoring return value of function declared with pure attribute}}
93 fn3(42); // expected-warning {{ignoring return value of function declared with const attribute}}
94 __builtin_abs(0); // expected-warning {{ignoring return value of function declared with const attribute}}
95 (void)0, fn1(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}}
99 int t7
__attribute__ ((warn_unused_result
)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
102 int (*fn4
)(void) __attribute__ ((warn_unused_result
));
104 fn4(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}}
107 void t9(void) __attribute__((warn_unused_result
)); // expected-warning {{attribute 'warn_unused_result' cannot be applied to functions without return value}}
110 void *some_function(void);
112 (void*) some_function(); //expected-warning {{expression result unused; should this cast be to 'void'?}}
116 __builtin_va_list ap
;
118 __builtin_va_start(ap
, i
);
119 __builtin_va_arg(ap
, int);
120 __builtin_va_end(ap
);
124 int fn5(void) __attribute__ ((__const
));
126 // Don't warn for unused expressions in macro bodies; however, do warn for
127 // unused expressions in macro arguments. Macros below are reduced from code
128 // found in the wild.
130 #define M1(a, b) (long)foo((a), (b))
132 #define M3(a) (t3(a), fn2())
133 #define M4(a, b) (foo((a), (b)) ? 0 : t3(a), 1)
134 #define M5(a, b) (foo((a), (b)), 1)
137 void t11(int i
, int j
) {
138 M1(i
, j
); // no warning
139 NOP((long)foo(i
, j
)); // expected-warning {{expression result unused}}
141 NOP((long)0); // expected-warning {{expression result unused}}
143 NOP((t3(i
), fn2())); // expected-warning {{ignoring return value}}
144 M4(i
, j
); // no warning
145 NOP((foo(i
, j
) ? 0 : t3(i
), 1)); // expected-warning {{expression result unused}}
146 M5(i
, j
); // no warning
147 NOP((foo(i
, j
), 1)); // expected-warning {{expression result unused}}
148 M6(); // expected-warning {{ignoring return value}}
160 #define UNREFERENCED_PARAMETER(x) (x)
162 void unused_parm(int a
) {
163 // Don't warn if the warning is introduced by a macro that's spelled
164 // UNREFERENCED_PARAMETER, as that's a commonly used macro in Windows headers.
165 UNREFERENCED_PARAMETER(a
);