forked from OSchip/llvm-project
Move string literal to bool conversion into its own warning flag -Wstring-conversion.
llvm-svn: 140574
This commit is contained in:
parent
02bb7573fb
commit
1db746afbf
|
@ -227,6 +227,7 @@ def Conversion : DiagGroup<"conversion",
|
|||
[DiagGroup<"shorten-64-to-32">,
|
||||
DiagGroup<"constant-conversion">,
|
||||
DiagGroup<"literal-conversion">,
|
||||
DiagGroup<"string-convervion">,
|
||||
DiagGroup<"sign-conversion">,
|
||||
BoolConversions]>,
|
||||
DiagCategory<"Value Conversion Issue">;
|
||||
|
|
|
@ -1478,7 +1478,7 @@ def warn_impcast_literal_float_to_integer : Warning<
|
|||
InGroup<DiagGroup<"literal-conversion">>, DefaultIgnore;
|
||||
def warn_impcast_string_literal_to_bool : Warning<
|
||||
"implicit conversion turns string literal into bool: %0 to %1">,
|
||||
InGroup<DiagGroup<"literal-conversion">>, DefaultIgnore;
|
||||
InGroup<DiagGroup<"string-conversion">>, DefaultIgnore;
|
||||
def note_fix_integral_float_as_integer : Note<
|
||||
"this can be rewritten as an integer literal with the exact same value">;
|
||||
def warn_impcast_different_enum_types : Warning<
|
||||
|
|
|
@ -43,19 +43,3 @@ void test0() {
|
|||
int y = (24*60*60) * 0.25;
|
||||
int pennies = 123.45 * 100;
|
||||
}
|
||||
|
||||
// Warn on cases where a string literal is converted into a bool.
|
||||
// An exception is made for this in logical operators.
|
||||
void assert(bool condition);
|
||||
void test1() {
|
||||
bool b0 = "hi"; // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
b0 = ""; // expected-warning{{implicit conversion turns string literal into bool: 'const char [1]' to 'bool'}}
|
||||
b0 = 0 && "";
|
||||
assert("error"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' to 'bool'}}
|
||||
assert(0 && "error");
|
||||
|
||||
while("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
do {} while("hi"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
for (;"hi";); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
if("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -Wstring-conversion -verify %s
|
||||
|
||||
// Warn on cases where a string literal is converted into a bool.
|
||||
// An exception is made for this in logical operators.
|
||||
void assert(bool condition);
|
||||
void test0() {
|
||||
bool b0 = "hi"; // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
b0 = ""; // expected-warning{{implicit conversion turns string literal into bool: 'const char [1]' to 'bool'}}
|
||||
b0 = 0 && "";
|
||||
assert("error"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [6]' to 'bool'}}
|
||||
assert(0 && "error");
|
||||
|
||||
while("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
do {} while("hi"); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
for (;"hi";); // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
if("hi") {} // expected-warning{{implicit conversion turns string literal into bool: 'const char [3]' to 'bool'}}
|
||||
}
|
||||
|
Loading…
Reference in New Issue