blob: 23960e48df6191af65ea3b5742cf8463219af92f [file] [log] [blame]
Richard Trieu02fa1b92011-09-26 22:38:21 +00001// 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 operators.
5void assert(bool condition);
6void 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 && "";
10 assert("error"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' to 'bool'}}
11 assert(0 && "error");
12
13 while("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
14 do {} while("hi"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
15 for (;"hi";); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
16 if("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
17}
18