1

I would expect the following code to produce a compiler error because the nested constraint within the requires clause is not a constant expression. However, Clang 15.0.0 seems to be okay with it and compiles it without any errors. This seems to be a regression compared to Clang version 14.0.0, which does produce the expected error. Is there a good reason for this change in behavior or is this simply a compiler bug of Clang?

struct s
{ static auto b() -> bool; };

template<typename T>
concept c = requires
{ requires T::b(); };

static_assert(not c<s>); // fails with Clang 14, GCC 12.2, and MSVC 19.32
303
  • 2,417
  • 1
  • 11
  • 25
  • Not sure about the standard, but clang 15 behaviour seems the more logical. as `s::b()` cannot be used in constant expression, `s` doesn't fulfil the concept. Sad to have hard error on that. – Jarod42 Sep 20 '22 at 13:10
  • There was a clang bug that required extra requireses. https://stackoverflow.com/questions/66562184/ad-hoc-constraint-requires-requires-requires-requires – Spencer Sep 20 '22 at 13:16
  • @Jarod42 It sure is. I was quite surprised to see `std::bool_constant` show up in some of the [concept definitions](https://en.cppreference.com/w/cpp/numeric/random/uniform_random_bit_generator) of the standard library. – 303 Sep 20 '22 at 13:19
  • Indeed, wrapping in `bool_constant` compiles on all compiler [Demo](https://godbolt.org/z/188ocf8Yr). But your argument about compile error because `s::b()` is not `constexpr` is not symmetrical... – Jarod42 Sep 20 '22 at 13:36

0 Answers0