unused-expr.c revision 5bef8ddabfe157aa6f1f9010d3d144215b3e731a
1// RUN: clang -fsyntax-only -verify -fno-math-errno %s
2
3int foo(int X, int Y);
4
5double sqrt(double X);  // implicitly const because of -fno-math-errno!
6
7void bar(volatile int *VP, int *P, int A,
8         _Complex double C, volatile _Complex double VC) {
9
10  VP == P;             // expected-warning {{expression result unused}}
11  (void)A;
12  (void)foo(1,2);      // no warning.
13
14  A == foo(1, 2);      // expected-warning {{expression result unused}}
15
16  foo(1,2)+foo(4,3);   // expected-warning {{expression result unused}}
17
18
19  *P;                  // expected-warning {{expression result unused}}
20  *VP;                 // no warning.
21  P[4];                // expected-warning {{expression result unused}}
22  VP[4];               // no warning.
23
24  __real__ C;          // expected-warning {{expression result unused}}
25  __real__ VC;
26
27  // We know this can't change errno because of -fno-math-errno.
28  sqrt(A);  // expected-warning {{expression result unused}}
29}
30
31extern void t1();
32extern void t2();
33void t3(int c) {
34  c ? t1() : t2();
35}
36
37// This shouldn't warn: the expr at the end of the stmtexpr really is used.
38int stmt_expr(int x, int y) {
39  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
40}
41
42void nowarn(unsigned char* a, unsigned char* b)
43{
44  unsigned char c = 1;
45  *a |= c, *b += c;
46}
47