Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

consteval broken? on Apple clang++

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(); }
                        ^

====================
EDIT: 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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading