You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Diagnostics] Warn for comparison with string literals expanded from macro (PR44064)
Summary:
As noted in PR, we have a poor test coverage for this warning. I think macro support was just overlooked. GCC warns in these cases.
Clang missed a real bug in the code I am working with, GCC caught it.
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70624
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
3
+
4
+
#defineDELIM "/"
5
+
#defineDOT "."
6
+
#defineNULL (void *)0
7
+
8
+
voidtest(constchar*d) {
9
+
if ("/"!=d) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
10
+
return;
11
+
if (d=="/") // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
12
+
return;
13
+
if ("/"!=NULL)
14
+
return;
15
+
if (NULL=="/")
16
+
return;
17
+
if ("/"!=DELIM) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
18
+
return;
19
+
if (DELIM=="/") // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
20
+
return;
21
+
if (DELIM!=NULL)
22
+
return;
23
+
if (NULL==DELIM)
24
+
return;
25
+
if (DOT!=DELIM) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
26
+
return;
27
+
if (DELIM==DOT) // expected-warning {{result of comparison against a string literal is unspecified (use an explicit string comparison function instead)}}
0 commit comments