Remove fixit for string literal comparison. Telling the user to use 'strcmp' is bad, and

we don't have enough information to tell them how to use 'strncmp'.  Instead, change the
diagnostic to indicate they should use 'strncmp'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100890 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2010-04-09 20:26:53 +00:00
Родитель c53e3658e6
Коммит 03a4bee558
4 изменённых файлов: 3 добавлений и 13 удалений

Просмотреть файл

@ -2718,7 +2718,7 @@ def warn_selfcomparison : Warning<
"self-comparison always results in a constant value">;
def warn_stringcompare : Warning<
"result of comparison against %select{a string literal|@encode}0 is "
"unspecified (use strcmp instead)">;
"unspecified (use strncmp instead)">;

Просмотреть файл

@ -5402,11 +5402,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
DiagRuntimeBehavior(Loc,
PDiag(diag::warn_stringcompare)
<< isa<ObjCEncodeExpr>(literalStringStripped)
<< literalString->getSourceRange()
<< FixItHint::CreateReplacement(SourceRange(Loc), ", ")
<< FixItHint::CreateInsertion(lex->getLocStart(), "strcmp(")
<< FixItHint::CreateInsertion(PP.getLocForEndOfToken(rex->getLocEnd()),
resultComparison));
<< literalString->getSourceRange());
}
}

Просмотреть файл

@ -31,9 +31,3 @@ void f1(x, y)
int i0 = { 17 };
int f2(const char *my_string) {
// FIXME: terminal output isn't so good when "my_string" is shorter
// CHECK: return strcmp(my_string , "foo") == 0;
return my_string == "foo";
}

Просмотреть файл

@ -84,7 +84,7 @@ void test11(struct mystruct P, float F) {
// PR3753
int test12(const char *X) {
return X == "foo"; // expected-warning {{comparison against a string literal is unspecified}}
return X == "foo"; // expected-warning {{comparison against a string literal is unspecified (use strncmp instead)}}
}
int test12b(const char *X) {