annotate clang/test/Sema/warn-string-conversion.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -verify -fsyntax-only -Wstring-conversion %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 void do_nothing();
anatofuz
parents:
diff changeset
4 void assert_error();
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 #define assert1(expr) \
anatofuz
parents:
diff changeset
7 if (expr) \
anatofuz
parents:
diff changeset
8 do_nothing(); \
anatofuz
parents:
diff changeset
9 else \
anatofuz
parents:
diff changeset
10 assert_error()
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 #define assert2(expr) \
anatofuz
parents:
diff changeset
13 ((expr) ? do_nothing() : assert_error())
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 // Exception for common assert form.
anatofuz
parents:
diff changeset
16 void test1() {
anatofuz
parents:
diff changeset
17 assert1(0 && "foo");
anatofuz
parents:
diff changeset
18 assert1("foo" && 0);
anatofuz
parents:
diff changeset
19 assert1(0 || "foo"); // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
20 assert1("foo"); // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 assert2(0 && "foo");
anatofuz
parents:
diff changeset
23 assert2("foo" && 0);
anatofuz
parents:
diff changeset
24 assert2(0 || "foo"); // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
25 assert2("foo"); // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 void test2() {
anatofuz
parents:
diff changeset
29 if ("hi") {} // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
30 while ("hello") {} // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
31 for (;"howdy";) {} // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
32 do { } while ("hey"); // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
33 int x = "hey" ? 1 : 2; // expected-warning {{string literal}}
anatofuz
parents:
diff changeset
34 }