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
"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)">;
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());
}
}
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";
-}
-
// 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) {