Aaron Ballman | 78ecb87 | 2014-10-16 20:13:28 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wunused-value %s |
Aaron Ballman | 78ecb87 | 2014-10-16 20:13:28 +0000 | [diff] [blame] | 2 | |
| 3 | void f() __attribute__((const)); |
| 4 | |
| 5 | namespace PR18571 { |
| 6 | // Unevaluated contexts should not trigger unused result warnings. |
| 7 | template <typename T> |
| 8 | auto foo(T) -> decltype(f(), bool()) { // Should not warn. |
| 9 | return true; |
| 10 | } |
| 11 | |
| 12 | void g() { |
| 13 | foo(1); |
| 14 | } |
Aaron Ballman | 6c93b3e | 2014-12-17 21:57:17 +0000 | [diff] [blame] | 15 | |
| 16 | void h() { |
| 17 | int i = 0; |
| 18 | (void)noexcept(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}} |
| 19 | decltype(i++) j = 0; // expected-warning {{expression with side effects has no effect in an unevaluated context}} |
Aaron Ballman | 78ecb87 | 2014-10-16 20:13:28 +0000 | [diff] [blame] | 20 | } |
Aaron Ballman | 6c93b3e | 2014-12-17 21:57:17 +0000 | [diff] [blame] | 21 | |
| 22 | struct S { |
| 23 | S operator++(int); |
| 24 | S(int i); |
| 25 | S(); |
| 26 | |
| 27 | int& f(); |
| 28 | S g(); |
| 29 | }; |
| 30 | |
| 31 | void j() { |
| 32 | S s; |
| 33 | int i = 0; |
| 34 | (void)noexcept(s++); // Ok |
| 35 | (void)noexcept(i++); // expected-warning {{expression with side effects has no effect in an unevaluated context}} |
| 36 | (void)noexcept(i = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}} |
| 37 | (void)noexcept(s = 5); // Ok |
| 38 | |
| 39 | (void)sizeof(s.f()); // Ok |
| 40 | (void)sizeof(s.f() = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}} |
| 41 | (void)noexcept(s.g() = 5); // Ok |
| 42 | } |
| 43 | |
| 44 | } |