[clang] [clang] Fixed inconsistent diagnostics when initializing a constexpr variable with a compound literal (PR #232825)

Abdulmalek Almkainzi via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 22 00:11:09 PDT 2026


aalmkainzi wrote:

@tbaederr @AaronBallman 

https://github.com/aalmkainzi/llvm-project/tree/disallow-non-null-constexpr-pointers-in-both-modes

In a branch off of the one of this PR, I added checks for non null pointers in both evaluators. I had to add `CheckNotNull` for the new constant interpreter, not sure if this is the best way to do it.

Should I merge it into this PR's branch?

so things like this would get rejected:
```C
constexpr struct C c2 = (struct C){&a};
```

Although, I'm having a bit of a problem with the tests. for some reason the following tests:
```C
constexpr struct C c2 = (struct C){&a}; // expected-error{{constexpr variable 'c2' must be initialized by a constant expression}}

constexpr union U u2 = (union U){.p = &a}; // expected-error{{constexpr variable 'u2' must be initialized by a constant expression}}
```
give these failures:
```
# | error: 'expected-error' diagnostics seen but not expected: 
# |   File /home/malek/repos/llvm-project/clang/test/Sema/constexpr.c Line 485: constexpr variable 'c2' must be initialized by a constant expression
# |   File /home/malek/repos/llvm-project/clang/test/Sema/constexpr.c Line 490: constexpr variable 'u2' must be initialized by a constant expression
# | 2 errors generated.
```
These are the errors I expected...

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


More information about the cfe-commits mailing list