зеркало из https://github.com/microsoft/clang-1.git
Implement a warning when converting the literal 'false' to a
pointer. Original patch by Troy D. Straszheim; fixes PR7283. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105621 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
2177ab7be5
Коммит
d7a95971bd
|
@ -23,6 +23,7 @@ def : DiagGroup<"aggregate-return">;
|
|||
def AmbigMemberTemplate : DiagGroup<"ambiguous-member-template">;
|
||||
def : DiagGroup<"attributes">;
|
||||
def : DiagGroup<"bad-function-cast">;
|
||||
def BoolConversions : DiagGroup<"bool-conversions">;
|
||||
def : DiagGroup<"c++-compat">;
|
||||
def : DiagGroup<"cast-align">;
|
||||
def : DiagGroup<"cast-qual">;
|
||||
|
@ -141,7 +142,7 @@ def Parentheses : DiagGroup<"parentheses", [DiagGroup<"idiomatic-parentheses">]>
|
|||
// -Wconversion has its own warnings, but we split this one out for
|
||||
// legacy reasons.
|
||||
def Conversion : DiagGroup<"conversion",
|
||||
[DiagGroup<"shorten-64-to-32">]>,
|
||||
[DiagGroup<"shorten-64-to-32">, BoolConversions]>,
|
||||
DiagCategory<"Value Conversion Issue">;
|
||||
|
||||
def Unused : DiagGroup<"unused",
|
||||
|
|
|
@ -1098,6 +1098,10 @@ def note_ovl_candidate : Note<"candidate "
|
|||
"is the implicit copy constructor|"
|
||||
"is the implicit copy assignment operator}0%1">;
|
||||
|
||||
def warn_init_pointer_from_false : Warning<
|
||||
"initialization of pointer of type %0 from literal 'false'">,
|
||||
InGroup<BoolConversions>;
|
||||
|
||||
def note_ovl_candidate_bad_deduction : Note<
|
||||
"candidate template ignored: failed template argument deduction">;
|
||||
def note_ovl_candidate_incomplete_deduction : Note<"candidate template ignored: "
|
||||
|
|
|
@ -1622,6 +1622,12 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType,
|
|||
bool IgnoreBaseAccess) {
|
||||
QualType FromType = From->getType();
|
||||
|
||||
if (CXXBoolLiteralExpr* LitBool
|
||||
= dyn_cast<CXXBoolLiteralExpr>(From->IgnoreParens()))
|
||||
if (LitBool->getValue() == false)
|
||||
Diag(LitBool->getExprLoc(), diag::warn_init_pointer_from_false)
|
||||
<< ToType;
|
||||
|
||||
if (const PointerType *FromPtrType = FromType->getAs<PointerType>())
|
||||
if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) {
|
||||
QualType FromPointeeType = FromPtrType->getPointeeType(),
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// 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'}}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче