[cfe-commits] r140574 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td test/SemaCXX/warn-literal-conversion.cpp test/SemaCXX/warn-string-conversion.cpp
Richard Trieu
rtrieu at google.com
Mon Sep 26 15:38:21 PDT 2011
Author: rtrieu
Date: Mon Sep 26 17:38:21 2011
New Revision: 140574
URL: http://llvm.org/viewvc/llvm-project?rev=140574&view=rev
Log:
Move string literal to bool conversion into its own warning flag -Wstring-conversion.
Added:
cfe/trunk/test/SemaCXX/warn-string-conversion.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=140574&r1=140573&r2=140574&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Sep 26 17:38:21 2011
@@ -227,6 +227,7 @@
[DiagGroup<"shorten-64-to-32">,
DiagGroup<"constant-conversion">,
DiagGroup<"literal-conversion">,
+ DiagGroup<"string-convervion">,
DiagGroup<"sign-conversion">,
BoolConversions]>,
DiagCategory<"Value Conversion Issue">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=140574&r1=140573&r2=140574&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 26 17:38:21 2011
@@ -1478,7 +1478,7 @@
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<
Modified: cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp?rev=140574&r1=140573&r2=140574&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp Mon Sep 26 17:38:21 2011
@@ -43,19 +43,3 @@
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'}}
-}
Added: cfe/trunk/test/SemaCXX/warn-string-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-string-conversion.cpp?rev=140574&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-string-conversion.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-string-conversion.cpp Mon Sep 26 17:38:21 2011
@@ -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'}}
+}
+
More information about the cfe-commits
mailing list