1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 
5 // PR4103 : Make sure we don't get a bogus unused expression warning
6 namespace PR4103 {
7   class APInt {
8     char foo;
9   };
10   class APSInt : public APInt {
11     char bar;
12   public:
13     APSInt &operator=(const APSInt &RHS);
14   };
15 
operator =(const APSInt & RHS)16   APSInt& APSInt::operator=(const APSInt &RHS) {
17     APInt::operator=(RHS);
18     return *this;
19   }
20 
21   template<typename T>
22   struct X {
23     X();
24   };
25 
test()26   void test() {
27     X<int>();
28   }
29 }
30 
31 namespace derefvolatile {
f(volatile char * x)32   void f(volatile char* x) {
33     *x;
34 #if __cplusplus <= 199711L
35     // expected-warning@-2 {{expression result unused; assign into a variable to force a volatile load}}
36 #endif
37     (void)*x;
38 #if __cplusplus <= 199711L
39     // expected-warning@-2 {{expression result unused; assign into a variable to force a volatile load}}
40 #endif
41     volatile char y = 10;
42     (void)y; // don't warn here, because it's a common pattern.
43   }
44 }
45 
46 // <rdar://problem/12359208>
47 namespace AnonObject {
48   struct Foo {
49     Foo(const char* const message);
50     ~Foo();
51   };
f()52   void f() {
53     Foo("Hello World!");  // don't warn
54     int(1); // expected-warning {{expression result unused}}
55   }
56 }
57 
58 // Test that constructing an object (which may have side effects) with
59 // constructor arguments which are dependent doesn't produce an unused value
60 // warning.
61 namespace UnresolvedLookup {
62   struct Foo {
63     Foo(int i, int j);
64   };
65   template <typename T>
66   struct Bar {
fUnresolvedLookup::Bar67     void f(T t) {
68       Foo(t, 0);  // no warning
69     }
70   };
71 }
72