comparison clang/test/SemaCXX/warn-string-conversion.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 1d019706d866
children
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
2 2
3 // Warn on cases where a string literal is converted into a bool. 3 // Warn on cases where a string literal is converted into a bool.
4 // An exception is made for this in logical and operators. 4 // An exception is made for this in logical and operators.
5 void assert(bool condition); 5 void assert(bool condition);
6 void test0() { 6 void test0() {
7 bool b0 = "hi"; // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}} 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'}} 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'}} 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'}} 10 b0 = "" || 0; // expected-warning{{implicit conversion turns string literal into bool: 'const char[1]' to 'bool'}}
11 b0 = 0 && ""; 11 b0 = 0 && "";
12 b0 = "" && 0; 12 b0 = "" && 0;
13 assert("error"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' 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'}} 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'}} 15 assert("error" || 0); // expected-warning{{implicit conversion turns string literal into bool: 'const char[6]' to 'bool'}}
16 assert(0 && "error"); 16 assert(0 && "error");
17 assert("error" && 0); 17 assert("error" && 0);
18 18
19 while("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' 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'}} 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'}} 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'}} 22 if("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char[3]' to 'bool'}}
23 } 23 }
24 24