diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-01-09 11:42:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-09 11:42:35 +0100 |
commit | fd6baa477fa13a4b893aeeba7fce92eb6a1f4962 (patch) | |
tree | 24dd2bba87b0a8afe7b364b9a1666a47510c4f92 /clang/test/AST/ByteCode/builtin-functions.cpp | |
parent | b79ed8729b3d6d5482481c41a7de2cd75b0f61df (diff) | |
download | llvm-fd6baa477fa13a4b893aeeba7fce92eb6a1f4962.zip llvm-fd6baa477fa13a4b893aeeba7fce92eb6a1f4962.tar.gz llvm-fd6baa477fa13a4b893aeeba7fce92eb6a1f4962.tar.bz2 |
[clang][ExprConst] Add diagnostics for invalid binary arithmetic (#118475)
... between unrelated declarations or literals.
Leaving this small (I haven't run the whole test suite locally) to get
some feedback on the wording and implementation first.
The output of the sample in
https://github.com/llvm/llvm-project/issues/117409 is now:
```console
./array.cpp:57:6: warning: expression result unused [-Wunused-value]
57 | am - aj.af();
| ~~ ^ ~~~~~~~
./array.cpp:70:8: error: call to consteval function 'L::L<bx>' is not a constant expression
70 | q(0, [] {
| ^
./array.cpp:57:6: note: arithmetic on addresses of literals has unspecified value
57 | am - aj.af();
| ^
./array.cpp:62:5: note: in call to 'al(&""[0], {&""[0]})'
62 | al(bp.af(), k);
| ^~~~~~~~~~~~~~
./array.cpp:70:8: note: in call to 'L<bx>({})'
70 | q(0, [] {
| ^~~~
71 | struct bx {
| ~~~~~~~~~~~
72 | constexpr operator ab<g<l<decltype(""[0])>::e>::e>() { return t(""); }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 | };
| ~~
74 | return bx();
| ~~~~~~~~~~~~
75 | }());
| ~~~
```
The output for
```c++
int a, b;
constexpr int n = &b - &a
```
is now:
```console
./array.cpp:80:15: error: constexpr variable 'n' must be initialized by a constant expression
80 | constexpr int n = &b - &a;
| ^ ~~~~~~~
./array.cpp:80:22: note: arithmetic involving '&b' and '&a' has unspecified value
80 | constexpr int n = &b - &a;
| ^
1 error generated.
```
Diffstat (limited to 'clang/test/AST/ByteCode/builtin-functions.cpp')
-rw-r--r-- | clang/test/AST/ByteCode/builtin-functions.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 7237640..7034e8c 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -1010,7 +1010,7 @@ namespace FunctionStart { void a(void) {} static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \ // ref-note {{comparison against opaque constant address '&__builtin_function_start(a)'}} \ - // expected-note {{comparison of addresses of literals has unspecified value}} + // expected-note {{comparison of addresses of potentially overlapping literals has unspecified value}} } namespace BuiltinInImplicitCtor { |