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 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 && ""; 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 19