From: Jordan Rose Date: Wed, 20 Aug 2014 16:51:18 +0000 (+0000) Subject: [analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef75d1308ca3e66a7a201117d74ba5e6a5a47c81;p=clang [analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals. PR20693. Patch by Anders Rönnholm. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216075 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp b/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp index d5c52b4c6a..ecb82c9031 100644 --- a/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp @@ -455,7 +455,7 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1, case Stmt::StringLiteralClass: { const StringLiteral *StringLit1 = cast(Stmt1); const StringLiteral *StringLit2 = cast(Stmt2); - return StringLit1->getString() == StringLit2->getString(); + return StringLit1->getBytes() == StringLit2->getBytes(); } case Stmt::MemberExprClass: { const MemberExpr *MemberStmt1 = cast(Stmt1); diff --git a/test/Analysis/identical-expressions.cpp b/test/Analysis/identical-expressions.cpp index 85e3322002..3c8040aed8 100644 --- a/test/Analysis/identical-expressions.cpp +++ b/test/Analysis/identical-expressions.cpp @@ -1511,3 +1511,10 @@ void test_nowarn_chained_if_stmts_3(int x) { else if (x++) // no-warning ; } + +void test_warn_wchar() { + const wchar_t * a = 0 ? L"Warning" : L"Warning"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}} +} +void test_nowarn_wchar() { + const wchar_t * a = 0 ? L"No" : L"Warning"; +}