]> granicus.if.org Git - clang/commitdiff
Remove fixit for string literal comparison. Telling the user to use 'strcmp' is...
authorTed Kremenek <kremenek@apple.com>
Fri, 9 Apr 2010 20:26:53 +0000 (20:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 9 Apr 2010 20:26:53 +0000 (20:26 +0000)
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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/FixIt/fixit.c
test/Sema/exprs.c

index 62769decf484ec9dca0d30d568118aba0e16101c..c21726ba7bdcc522d7dcebd365549bc69db5ce2d 100644 (file)
@@ -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)">;
 
 
 
index 654b22049952afedc0747a7bc70c5a1464a8aae4..6820449e1c8d489e99de5d7f1c92340c03073202 100644 (file)
@@ -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());
     }
   }
 
index 83d724dffc01af9020a65e0b4c94cb1e8c231e80..7ee5575cf2358463a98aa954d46b1cdb7a3f4309 100644 (file)
@@ -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";
-}
-
index 9acc63fa41a5e5725597b91dd2022630031bb73b..4df8188e434ec3b41560a6ae9861ad80e88d84c5 100644 (file)
@@ -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) {