1 | // RUN: %clang_cc1 -fsyntax-only -Wstring-conversion -verify %s |
2 | |
3 | // Warn on cases where a string literal is converted into a bool. |
4 | // An exception is made for this in logical and operators. |
5 | void assert(bool condition); |
6 | void test0() { |
7 | bool b0 = "hi"; // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}} |
8 | b0 = ""; // expected-warning{{implicit conversion turns string literal into bool: 'const char [1]' to 'bool'}} |
9 | b0 = 0 || ""; // expected-warning{{implicit conversion turns string literal into bool: 'const char [1]' to 'bool'}} |
10 | b0 = "" || 0; // expected-warning{{implicit conversion turns string literal into bool: 'const char [1]' to 'bool'}} |
11 | b0 = 0 && ""; |
12 | b0 = "" && 0; |
13 | assert("error"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' to 'bool'}} |
14 | assert(0 || "error"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' to 'bool'}} |
15 | assert("error" || 0); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' to 'bool'}} |
16 | assert(0 && "error"); |
17 | assert("error" && 0); |
18 | |
19 | while("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}} |
20 | do {} while("hi"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}} |
21 | for (;"hi";); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}} |
22 | if("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}} |
23 | } |
24 | |
25 | |