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