Richard Trieu | 791b86e | 2014-11-19 06:08:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -Wstring-conversion %s |
| 2 | |
Richard Trieu | cbab79a | 2015-05-20 23:29:18 +0000 | [diff] [blame] | 3 | void do_nothing(); |
| 4 | void assert_error(); |
| 5 | |
| 6 | #define assert1(expr) \ |
| 7 | if (expr) \ |
| 8 | do_nothing(); \ |
| 9 | else \ |
| 10 | assert_error() |
| 11 | |
| 12 | #define assert2(expr) \ |
| 13 | ((expr) ? do_nothing() : assert_error()) |
Richard Trieu | 791b86e | 2014-11-19 06:08:18 +0000 | [diff] [blame] | 14 | |
| 15 | // Expection for common assert form. |
| 16 | void test1() { |
Richard Trieu | cbab79a | 2015-05-20 23:29:18 +0000 | [diff] [blame] | 17 | assert1(0 && "foo"); |
| 18 | assert1("foo" && 0); |
| 19 | assert1(0 || "foo"); // expected-warning {{string literal}} |
| 20 | assert1("foo"); // expected-warning {{string literal}} |
| 21 | |
| 22 | assert2(0 && "foo"); |
| 23 | assert2("foo" && 0); |
| 24 | assert2(0 || "foo"); // expected-warning {{string literal}} |
| 25 | assert2("foo"); // expected-warning {{string literal}} |
Richard Trieu | 791b86e | 2014-11-19 06:08:18 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void test2() { |
| 29 | if ("hi") {} // expected-warning {{string literal}} |
| 30 | while ("hello") {} // expected-warning {{string literal}} |
| 31 | for (;"howdy";) {} // expected-warning {{string literal}} |
| 32 | do { } while ("hey"); // expected-warning {{string literal}} |
Richard Trieu | cbab79a | 2015-05-20 23:29:18 +0000 | [diff] [blame] | 33 | int x = "hey" ? 1 : 2; // expected-warning {{string literal}} |
Richard Trieu | 791b86e | 2014-11-19 06:08:18 +0000 | [diff] [blame] | 34 | } |