[clang] [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149227)

A. Jiang via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 28 03:09:56 PDT 2025


frederick-vs-ja wrote:

Looks like there're still some other false-positive cases (https://godbolt.org/z/1G9WPn9de):

```C++
constexpr bool same_address(const int &a, const int &b) { return &a == &b; }
constexpr int next_element(const int &p) { return (&p)[2]; }

struct Base {};
struct Derived : Base { int n; };
constexpr int get_derived_member(const Base& b) { return static_cast<const Derived&>(b).n; }

struct PolyBase {
  constexpr virtual int get() const { return 0; }
};
struct PolyDerived : PolyBase {
  constexpr int get() const override { return 1; }
};
constexpr int virtual_call(const PolyBase& b) { return b.get(); }

constexpr int arr[3]{0, 1, 2};
static_assert(same_address(arr[1], arr[1]));
static_assert(next_element(arr[0]) == 2);

static_assert(get_derived_member(Derived{}) == 0);
static_assert(virtual_call(PolyDerived{}) == 1);
```

https://github.com/llvm/llvm-project/pull/149227


More information about the cfe-commits mailing list