[cfe-commits] r129205 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/SemaCXX/warn-bool-conversion.cpp test/SemaCXX/warn_false_to_pointer.cpp
Chandler Carruth
chandlerc at gmail.com
Sat Apr 9 00:48:17 PDT 2011
Author: chandlerc
Date: Sat Apr 9 02:48:17 2011
New Revision: 129205
URL: http://llvm.org/viewvc/llvm-project?rev=129205&view=rev
Log:
Clean up the bool conversion warning. Group it with other conversion
warnings, and make its text appropriate for constant bool expressions
other than 'false'. This should finish off PR9612.
Added:
cfe/trunk/test/SemaCXX/warn-bool-conversion.cpp
- copied, changed from r129204, cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp
Removed:
cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=129205&r1=129204&r2=129205&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Apr 9 02:48:17 2011
@@ -1197,6 +1197,10 @@
def warn_impcast_different_enum_types : Warning<
"implicit conversion from enumeration type %0 to different enumeration type "
"%1">, InGroup<DiagGroup<"conversion">>;
+def warn_impcast_bool_to_null_pointer : Warning<
+ "initialization of pointer of type %0 to NULL from a constant boolean "
+ "expression">, InGroup<BoolConversions>;
+
def warn_cast_align : Warning<
"cast from %0 to %1 increases required alignment from %2 to %3">,
@@ -1367,10 +1371,6 @@
"is the implicit copy assignment operator|"
"is an inherited constructor}0%1">;
-def warn_init_pointer_from_false : Warning<
- "initialization of pointer of type %0 from literal 'false'">,
- InGroup<BoolConversions>;
-
def note_ovl_candidate_inherited_constructor : Note<"inherited from here">;
def note_ovl_candidate_bad_deduction : Note<
"candidate template ignored: failed template argument deduction">;
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=129205&r1=129204&r2=129205&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Apr 9 02:48:17 2011
@@ -1986,7 +1986,8 @@
Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy) &&
From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
DiagRuntimeBehavior(From->getExprLoc(), From,
- PDiag(diag::warn_init_pointer_from_false) << ToType);
+ PDiag(diag::warn_impcast_bool_to_null_pointer)
+ << ToType << From->getSourceRange());
if (const PointerType *FromPtrType = FromType->getAs<PointerType>())
if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) {
Copied: cfe/trunk/test/SemaCXX/warn-bool-conversion.cpp (from r129204, cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-bool-conversion.cpp?p2=cfe/trunk/test/SemaCXX/warn-bool-conversion.cpp&p1=cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp&r1=129204&r2=129205&rev=129205&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-bool-conversion.cpp Sat Apr 9 02:48:17 2011
@@ -1,18 +1,18 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-int* j = false; // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+int* j = false; // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
-void foo(int* i, int *j=(false)) // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+void foo(int* i, int *j=(false)) // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
{
- foo(false); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+ foo(false); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
foo((int*)false); // no-warning: explicit cast
foo(0); // no-warning: not a bool, even though its convertible to bool
- foo(false == true); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
- foo((42 + 24) < 32); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+ foo(false == true); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
+ foo((42 + 24) < 32); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
const bool kFlag = false;
- foo(kFlag); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+ foo(kFlag); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
}
char f(struct Undefined*);
Removed: cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp?rev=129204&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn_false_to_pointer.cpp (removed)
@@ -1,24 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-int* j = false; // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
-
-void foo(int* i, int *j=(false)) // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
-{
- foo(false); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
- foo((int*)false); // no-warning: explicit cast
- foo(0); // no-warning: not a bool, even though its convertible to bool
-
- foo(false == true); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
- foo((42 + 24) < 32); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
-
- const bool kFlag = false;
- foo(kFlag); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
-}
-
-char f(struct Undefined*);
-double f(...);
-
-// Ensure that when using false in metaprogramming machinery its conversion
-// isn't flagged.
-template <int N> struct S {};
-S<sizeof(f(false))> s;
More information about the cfe-commits
mailing list