John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value %s |
| 2 | |
| 3 | // PR4806 |
| 4 | namespace test0 { |
| 5 | class Box { |
| 6 | public: |
| 7 | int i; |
| 8 | volatile int j; |
| 9 | }; |
| 10 | |
| 11 | void doit() { |
| 12 | // pointer to volatile has side effect (thus no warning) |
| 13 | Box* box = new Box; |
| 14 | box->i; // expected-warning {{expression result unused}} |
Eli Friedman | a611506 | 2012-05-24 00:47:05 +0000 | [diff] [blame] | 15 | box->j; // expected-warning {{expression result unused}} |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 16 | } |
| 17 | } |
Matt Beaumont-Gay | 6e52183 | 2011-09-19 18:51:20 +0000 | [diff] [blame] | 18 | |
| 19 | namespace test1 { |
| 20 | struct Foo { |
| 21 | int i; |
| 22 | bool operator==(const Foo& rhs) { |
| 23 | return i == rhs.i; |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | #define NOP(x) (x) |
| 28 | void b(Foo f1, Foo f2) { |
| 29 | NOP(f1 == f2); // expected-warning {{expression result unused}} |
| 30 | } |
| 31 | #undef NOP |
| 32 | } |
Nick Lewycky | 5a7120c | 2012-03-14 20:41:00 +0000 | [diff] [blame] | 33 | |
| 34 | namespace test2 { |
| 35 | extern "C" { |
| 36 | namespace std { |
| 37 | template<typename T> struct basic_string { |
| 38 | struct X {}; |
| 39 | void method() const { |
| 40 | X* x; |
| 41 | &x[0]; // expected-warning {{expression result unused}} |
| 42 | } |
| 43 | }; |
| 44 | typedef basic_string<char> string; |
| 45 | void func(const std::string& str) { |
| 46 | str.method(); // expected-note {{in instantiation of member function}} |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |