https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127750
--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
I believe that the same cause makes the following incorrectly fail to compile
with -std=c++17:
#include <typeinfo>
struct T {
virtual ~T();
};
void h(T* p)
{
(void)typeid(*[&]{ return p; }()); // operand is, as far as I can tell,
evaluated
}
template<class T> void tmpl(T* p)
{
(void)typeid(*[&]{ return p; }()); // operand is, as far as I can tell,
evaluated
}
<source>: In function 'void h(T*)':
<source>:8:19: error: lambda-expression in unevaluated context only available
with '-std=c++20' or '-std=gnu++20'
8 | (void)typeid(*[&]{ return p; }()); // operand is, as far as I can
tell, evaluated
| ^
<source>: In function 'void tmpl(T*)':
<source>:14:19: error: lambda-expression in unevaluated context only available
with '-std=c++20' or '-std=gnu++20' [-Wtemplate-body]
14 | (void)typeid(*[&]{ return p; }()); // operand is, as far as I can
tell, evaluated
| ^
...despite that the operands seem rather quite evaluated to me.
This program also I believe is ill-formed for all three functions but GCC trunk
throws no errors at all:
#include <typeinfo>
#include <utility>
struct B { virtual ~B(); };
struct F final { virtual ~F(); };
void f1() { B b; [] { (void)typeid(b); }; }
void f2(F& r) { [] { (void)typeid(r); }; }
void f3() { (void)typeid(std::declval<F>()); }
GCC 16.2 gives three errors.
This program also I believe should throw:
#include <typeinfo>
struct F final { virtual ~F(); };
F::~F() {}
int main() { (void)typeid(*static_cast<F*>(nullptr)); }
...but it doesn't (this may be a regression older than GCC 16?)
(PS: I do not appear to have the permissions to assign ppl to bugs on the GCC
bugzilla)