According to this, a function declared with constexpr
must satisfy a few requirements, one of which is as follows:
there exists at least one argument value such that an invocation of the function could be an evaluated subexpression of a core constant expression ...
Well, constexpr
function can have no arguments:
constexpr int Bar( /* empty */ ) { return 0xFF; }
constexpr int value = Bar(); // Valid expression
constexpr
function that is invoked as a sub-routine can not determine the whole expression to be core constant expression either.
So what does it mean by one argument value must exist?
[Update for future readers]
Apparently the description about the requirements of constexpr function
has been fixed since this question from:
there exists at least one argument value such that an invocation of the function could be an evaluated subexpression of a core constant expression ...
to:
there exists at least one set of argument values such that an invocation of the function could be an evaluated subexpression of a core constant expression ...
The quote from en.cppreference.com is not accurate in regards to the standard, the real quote is (§7.1.5/5):
For a
constexpr
function orconstexpr
constructor that is neither defaulted nor a template, if no argument values exist such that an invocation of the function or constructor could be an evaluated subexpression of a core constant expression (5.20) [...] the program is ill-formed; no diagnostic required.
Which basically says that there must exist one valid set of arguments (the empty set being a valid one in your case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With