[Bug c++/108218] [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand
StevenSun2021 at hotmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 24 16:00:41 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108218
--- Comment #1 from Steven Sun <StevenSun2021 at hotmail dot com> ---
My concern is that, expressions within the require expressions are also
considered as "unevaluated operands".
Thus, the following concept is evaluated as true, but the program is ill-formed
and does not compile (since gcc 12)
https://godbolt.org/z/bcc398chG
```
template<class T>
concept C = requires
{
new int[(int)sizeof(T) - 4];
};
template<typename T> requires C<T>
class CC {
CC() {
new int[(int)sizeof(T) - 4];
}
};
template class CC<char>;
```
<source>: In instantiation of 'CC<T>::CC() [with T = char]':
<source>:16:16: required from here
<source>:12:32: error: size '-3' of array is negative
12 | new int[(int)sizeof(T) - 4];
| ~~~~~~~~~~~~~~~^~~
More information about the Gcc-bugs
mailing list