Revert "[clang][ExprConst] Allow comparisons with string literals (#106733)"
This reverts commit 5d1d2f08c4a92580e7f6b3b6b77b2b6f6184e126. See the discussion in https://github.com/llvm/llvm-project/pull/106733 and https://github.com/llvm/llvm-project/issues/58754
This commit is contained in:
parent
884221eddb
commit
95a0b4f729
@ -2146,7 +2146,7 @@ static bool IsLiteralLValue(const LValue &Value) {
|
|||||||
if (Value.getLValueCallIndex())
|
if (Value.getLValueCallIndex())
|
||||||
return false;
|
return false;
|
||||||
const Expr *E = Value.Base.dyn_cast<const Expr*>();
|
const Expr *E = Value.Base.dyn_cast<const Expr*>();
|
||||||
return E && !isa<MaterializeTemporaryExpr, StringLiteral>(E);
|
return E && !isa<MaterializeTemporaryExpr>(E);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsWeakLValue(const LValue &Value) {
|
static bool IsWeakLValue(const LValue &Value) {
|
||||||
|
@ -108,16 +108,22 @@ constexpr auto p2 = "test2";
|
|||||||
constexpr bool b1 = foo(p1) == foo(p1);
|
constexpr bool b1 = foo(p1) == foo(p1);
|
||||||
static_assert(b1);
|
static_assert(b1);
|
||||||
|
|
||||||
constexpr bool b2 = foo(p1) == foo(p2);
|
constexpr bool b2 = foo(p1) == foo(p2); // ref-error {{must be initialized by a constant expression}} \
|
||||||
static_assert(!b2);
|
// ref-note {{comparison of addresses of literals}} \
|
||||||
|
// ref-note {{declared here}}
|
||||||
|
static_assert(!b2); // ref-error {{not an integral constant expression}} \
|
||||||
|
// ref-note {{not a constant expression}}
|
||||||
|
|
||||||
constexpr auto name1() { return "name1"; }
|
constexpr auto name1() { return "name1"; }
|
||||||
constexpr auto name2() { return "name2"; }
|
constexpr auto name2() { return "name2"; }
|
||||||
|
|
||||||
constexpr auto b3 = name1() == name1();
|
constexpr auto b3 = name1() == name1();
|
||||||
static_assert(b3);
|
static_assert(b3);
|
||||||
constexpr auto b4 = name1() == name2();
|
constexpr auto b4 = name1() == name2(); // ref-error {{must be initialized by a constant expression}} \
|
||||||
static_assert(!b4);
|
// ref-note {{has unspecified value}} \
|
||||||
|
// ref-note {{declared here}}
|
||||||
|
static_assert(!b4); // ref-error {{not an integral constant expression}} \
|
||||||
|
// ref-note {{not a constant expression}}
|
||||||
|
|
||||||
namespace UninitializedFields {
|
namespace UninitializedFields {
|
||||||
class A {
|
class A {
|
||||||
|
@ -358,9 +358,11 @@ struct Str {
|
|||||||
|
|
||||||
extern char externalvar[];
|
extern char externalvar[];
|
||||||
constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} expected-note {{reinterpret_cast}}
|
constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} expected-note {{reinterpret_cast}}
|
||||||
constexpr bool litaddress = "foo" == "foo"; // cxx20_23-warning {{comparison between two arrays is deprecated}}
|
constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expression}}
|
||||||
|
// expected-note@-1 {{comparison of addresses of literals has unspecified value}}
|
||||||
|
// cxx20_23-warning@-2 {{comparison between two arrays is deprecated}}
|
||||||
static_assert(0 != "foo", "");
|
static_assert(0 != "foo", "");
|
||||||
static_assert("foo" != "foo", "");// cxx20_23-warning {{comparison between two arrays is deprecated}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MaterializeTemporary {
|
namespace MaterializeTemporary {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user