-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed
Closed
Copy link
Labels
bugzillaIssues migrated from bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Description
| Bugzilla Link | 12463 |
| Version | trunk |
| OS | Linux |
| Attachments | clang patch, clang patch |
Extended Description
$ cat a.cpp
#define FOO "foo"
#define BAR "bar"
bool foo()
{
bool b;
b = FOO == BAR;
b = "foo" == "bar";
return b;
}$ clang++ -Wall a.cpp -c
a.cpp:7:15: warning: result of comparison against a string literal is unspecified (use strncmp instead) [-Wstring-compare]
b = "foo" == "bar";
~~~~~ ^
1 warning generated.
Line 6 should generate a warning as well. As the warning says, the result of such a comparison is unspecified, so it is never correct, even if it comes from a macro expansion.
Metadata
Metadata
Assignees
Labels
bugzillaIssues migrated from bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer