1 // RUN: %clang_cc1 -fsyntax-only -Wstring-conversion -verify %s
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
);
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'}}
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'}}
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'}}