blob: 28dfc1b67dd5ebb7c8cedfacdeee1cff55de9447 [file] [log] [blame]
Richard Trieu791b86e2014-11-19 06:08:18 +00001// RUN: %clang_cc1 -verify -fsyntax-only -Wstring-conversion %s
2
Richard Trieucbab79a2015-05-20 23:29:18 +00003void do_nothing();
4void 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 Trieu791b86e2014-11-19 06:08:18 +000014
15// Expection for common assert form.
16void test1() {
Richard Trieucbab79a2015-05-20 23:29:18 +000017 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 Trieu791b86e2014-11-19 06:08:18 +000026}
27
28void 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 Trieucbab79a2015-05-20 23:29:18 +000033 int x = "hey" ? 1 : 2; // expected-warning {{string literal}}
Richard Trieu791b86e2014-11-19 06:08:18 +000034}