<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117409>117409</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Function call without comparisons reported as non-constant expression after CWG2765 implementation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++20,
clang:diagnostics,
clang:analysis
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ormris
</td>
</tr>
</table>
<pre>
We're seeing a new diagnostic trigger in an internal test. The diagnostic is implemented in...
```
commit d8a281590311010955c323806fb24fa484376f4d
Author: Richard Smith <richard@metafoo.co.uk>
Date: Thu Sep 26 15:56:33 2024 -0700
[clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (#109208)
Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.
---------
Co-authored-by: Timm Baeder <tbaeder@redhat.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
```
Reduced test case below. The test case and CWG document seem to indicate that comparison is the expected use case, but I don't see any comparison operations in the code below. The values returned by the function indicated in the diagnostic are constant as well.
```
template <class> struct g;
template <class b> struct g<const b> { using e = b; };
template <class> struct l;
template <class b> struct l<b &> { using e = b; };
template <typename aa> struct ab {
const aa *ac;
ab();
constexpr ab(const aa *k, long) : ac(k) {}
constexpr auto af() { return ac; }
};
constexpr void al(const char *am, ab<char> aj) {
am - aj.af();
}
struct L {
ab<char> bp;
template <typename o> consteval L(o k) : bp(k) {
al(bp.af(), k);
}
};
template <typename br> void q(br, L);
template <typename aa, int s> constexpr auto t(const aa (&k)[s]) -> ab<aa> {
return {k, s};
}
void e() {
q(0, [] {
struct bx {
constexpr operator ab<g<l<decltype(""[0])>::e>::e>() { return t(""); }
};
return bx();
}());
}
```
To reproduce:
```
$ clang -std=c++20 test.cpp
test.cpp:12:6: warning: expression result unused [-Wunused-value]
12 | am - aj.af();
| ~~ ^ ~~~~~~~
test.cpp:25:8: error: call to consteval function 'L::L<bx>' is not a constant expression
25 | q(0, [] {
| ^
test.cpp:12:6: note: subexpression not valid in a constant expression
12 | am - aj.af();
| ~~~^~~~~~~~~
test.cpp:17:5: note: in call to 'al(&""[0], {&""[0]})'
17 | al(bp.af(), k);
| ^~~~~~~~~~~~~~
test.cpp:25:8: note: in call to 'L<bx>({})'
25 | q(0, [] {
| ^~~~
26 | struct bx {
| ~~~~~~~~~~~
27 | constexpr operator ab<g<l<decltype(""[0])>::e>::e>() { return t(""); }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 | };
| ~~
29 | return bx();
| ~~~~~~~~~~~~
30 | }());
| ~~~
1 warning and 1 error generated.
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWEtv6zoO_jXKhkjgyHacLLLIo70YoKt7C5w1bTOJT2XJI8l9bM5vH1B2bKcn7Z2LWUxQ5CGL5MePD1FF56qzJtqKdC_S4wxbfzF2a2xtKzfLTfmx_UFCZpbAEVX6DAia3qCs8KyN81UB3lbnM1moNKCGSnuyGhV4cn4Bzxea7q0cVHWjqCbtqYRKLxYLER1FtOvfV1H_F34Wpq4rD-Ua5XqZbqJ4uYyW0SZNi1jG62h1ymVywmSdxNnqlJSd0C64IOId_FkVF7Ql_FVX_gIiPthuQSRRTR5PxiwKs2hfRPzQiR7REwsCPF9a-IsakCtYpiLepSsR7-IYZCQTmEdZFE1hg0j3hUJ9FulxdBCK1lr-LCtLha-MBnOCw48_ZLZK4WQsOG-ZUlV5sqigMHWDtnJGO2azMNp51B7oFVWLQYGQayHjZbSR0VrIzQ0Ihm2xeAF_IahK0r7yH2ySsLh8tmXyn1R4aKwp24JKyD8mZkaFb8wcwlmZHBW8knWMQrd1TnYBu6Kgxt_gzsm_EemrHcf2_YVGjQ5ruioS8gCoy7tCZ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