<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/150131>150131</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-21 regression: "enable_if attribute expression never produces a constant expression" when compiling LLVM in C++23
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vogelsgesang
</td>
</tr>
</table>
<pre>
The command
```
echo '#include "llvm/ADT/StringExtras.h"' | clang++-21 -x c++ - -I -std=c++23
```
fails with the compilation error
```
In file included from <stdin>:1:
In file included from ./llvm/include/llvm/ADT/StringExtras.h:19:
In file included from ./llvm/include/llvm/ADT/SmallString.h:18:
./llvm/include/llvm/ADT/StringRef.h:871:22: error: 'enable_if' attribute
expression never produces a constant expression
871 | __attribute((enable_if(__builtin_strlen(Str) == N - 1,
| ^
./llvm/include/llvm/ADT/StringExtras.h:150:34: note: in instantiation of
function template specialization 'llvm::StringLiteral::StringLiteral<33UL>' requested here
150 | static constexpr StringLiteral Punctuations =
| ^
./llvm/include/llvm/ADT/StringRef.h:871:49: note: read of variable 'Str'
whose value is not known
871 | __attribute((enable_if(__builtin_strlen(Str) == N - 1,
| ^
./llvm/include/llvm/ADT/StringRef.h:867:42: note: declared here
867 | constexpr StringLiteral(const char (&Str)[N])
| ^
1 error generated.
```
Both clang-21 and the used LLVM source were taken from the 21.1.0-rc1 tag.
The same command works against clang++ version 20, as such this is a regression compared to clang-20.
(The issue goes away when using C++20 instead of C++23)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVVGP4jYQ_jXmZQRyxoSEhzxkYZFO2p6q3rWvyCSTxF1jU9uBvf76ykkW2O5W6rUPZ0WCOPbM930z_iy9V60hKlj6wNLtTPahs64425a0b8lL084Otv5WfO0IKns8SlMD42V8Vnx6eElVZ4FhxlAoU-m-JmCIWp-PDHfl9ivD3ZfglGkfX4KTftEx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