Skip to content

Commit eb045ba

Browse files
tbaederrtmsri
authored andcommitted
Revert "[clang][ExprConst] Allow comparisons with string literals (llvm#106733)"
This reverts commit 5d1d2f0. See the discussion in llvm#106733 and llvm#58754
1 parent 124d479 commit eb045ba

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ static bool IsLiteralLValue(const LValue &Value) {
21462146
if (Value.getLValueCallIndex())
21472147
return false;
21482148
const Expr *E = Value.Base.dyn_cast<const Expr*>();
2149-
return E && !isa<MaterializeTemporaryExpr, StringLiteral>(E);
2149+
return E && !isa<MaterializeTemporaryExpr>(E);
21502150
}
21512151

21522152
static bool IsWeakLValue(const LValue &Value) {

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,22 @@ constexpr auto p2 = "test2";
108108
constexpr bool b1 = foo(p1) == foo(p1);
109109
static_assert(b1);
110110

111-
constexpr bool b2 = foo(p1) == foo(p2);
112-
static_assert(!b2);
111+
constexpr bool b2 = foo(p1) == foo(p2); // ref-error {{must be initialized by a constant expression}} \
112+
// ref-note {{comparison of addresses of literals}} \
113+
// ref-note {{declared here}}
114+
static_assert(!b2); // ref-error {{not an integral constant expression}} \
115+
// ref-note {{not a constant expression}}
113116

114117
constexpr auto name1() { return "name1"; }
115118
constexpr auto name2() { return "name2"; }
116119

117120
constexpr auto b3 = name1() == name1();
118121
static_assert(b3);
119-
constexpr auto b4 = name1() == name2();
120-
static_assert(!b4);
122+
constexpr auto b4 = name1() == name2(); // ref-error {{must be initialized by a constant expression}} \
123+
// ref-note {{has unspecified value}} \
124+
// ref-note {{declared here}}
125+
static_assert(!b4); // ref-error {{not an integral constant expression}} \
126+
// ref-note {{not a constant expression}}
121127

122128
namespace UninitializedFields {
123129
class A {

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,11 @@ struct Str {
358358

359359
extern char externalvar[];
360360
constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} expected-note {{reinterpret_cast}}
361-
constexpr bool litaddress = "foo" == "foo"; // cxx20_23-warning {{comparison between two arrays is deprecated}}
361+
constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expression}}
362+
// expected-note@-1 {{comparison of addresses of literals has unspecified value}}
363+
// cxx20_23-warning@-2 {{comparison between two arrays is deprecated}}
362364
static_assert(0 != "foo", "");
363-
static_assert("foo" != "foo", "");// cxx20_23-warning {{comparison between two arrays is deprecated}}
365+
364366
}
365367

366368
namespace MaterializeTemporary {

0 commit comments

Comments
 (0)