Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird return value of C++20 requires expression

Consider the requires expression:

constexpr auto b = requires { []{}; };

GCC pass the following two static_assert:

 static_assert(b);
 static_assert(!b); 

This looks extremely weird. I expect that the value of b should be true. Is this just a GCC Bug?

like image 577
康桓瑋 Avatar asked Mar 11 '21 08:03

康桓瑋


Video Answer


1 Answers

This isn't Schrödinger's Requirement: b should clearly be either true or false.

The requirement here:

constexpr auto b = requires { []{}; };

is a simple-requirement. We're just checking that if the expression []{} is a valid expression. And... it is! So b should just be true. This is a gcc bug (and doubly so with StoryTeller's example demonstrating that in a slighly different spelling b doesn't even count as a constant expression).

like image 116
Barry Avatar answered Oct 19 '22 19:10

Barry