When a function template is declared as aconstexprfunction, if the instantiation results in a function that does not satisfy the requirements of aconstexprfunction, theconstexprspecifier is ignored. For example: template <class C> constexpr NL f6(C c) { // OK, the constexpr specifier ignore...
if (is_this_parameter (x)) { if (DECL_CONSTRUCTOR_P (DECL_CONTEXT (x))) { if (flags & tf_error) sorry ("calling a member function of the " "object being constructed in a constant " "expression"); return false; } /* Otherwise OK. */; } else if (!potential_constant_expression...
if (is_this_parameter (x)) { if (DECL_CONSTRUCTOR_P (DECL_CONTEXT (x))) { if (flags & tf_error) sorry ("calling a member function of the " "object being constructed in a constant " "expression"); return false; } /* Otherwise OK. */; } else if (!potential_constant_expression...
exp2(x * x, n / 2) : exp2(x * x, (n - 1) / 2) * x; } // Compile-time computation of array length template<typename T, int N> constexpr int length(const T(&)[N]) { return N; } // Recursive constexpr function constexpr int fac(int n) { return n == 1 ? 1 :...
:6:18: error: constexpr variable 'result' must be initialized by a constant expression 6 | constexpr auto result = _.value; | ^ ~~~ :6:27: note: function parameter '_' with unknown value cannot be used in a constant expression 6 | constexpr auto result = _.value; | ^ :5:14:...
Default use of std::source_location means adding it as a default parameter to the log function. If the log function is a variadic template of the form log(fmtstr, args...) adding a default parameter is non-trivial.Replacing the macros with constexpr functions makes no sense because ...
Q2:条件不应该是sizeof...(rest) > 1吗?因为如果大小是1,我再次调用printArgs,那么rest不是空的...
参数来调用。Q1:为什么我需要constexpr在if中的程序编译?如果删除constexpr,则会得到以下error:...
conversion is not constexpr. constexpr D3(const D1 &d) : B2(), mem(d) { } //error, parameter NL is a non-literal type. constexpr D3(NL) : B2(), mem(55) { } private: int mem; };
我假设你使用GCC和-Wextra,否则我不会得到未使用的参数警告。请考虑以下代码: