consteval broken? on Apple clang++

238 views Asked by At

What doe the diagnostic below mean? I do not understand how a call to a correct consteval function with no arguments can possibly be anything other than a constant expression.

#include <iostream>
template<int x>
struct X {
consteval static int get() { return x; }
int f() const { return get(); }
};

int main() {
  ::std::cout << X<4>().get() << ::std::endl;
}
~/felix>clang++ -std=c++20 -ferror-limit=1 xx.cxx
xx.cxx:4:17: error: call to consteval function 'X::get' is not a constant expression
int f() const { return get(); }
                        ^

clang is confused. Here's the proof: this works:

int f() const { int a[get()]; return sizeof(a); }

clang thinks a consteval function can ONLY be used in a context where a constant expression is required: whether or not that is the rule in the Standard it's nonsense. In my actual code, the function is successfully called without a diagnostic if qualified by a template typename parameter, and is used in a context which does not require a constant.

1

There are 1 answers

1
user12002570 On BEST ANSWER

The program is well-formed and this is a clang bug which has been fixed in clang 15.0.

Demo