The following code is fine:
constexpr double square_cstxpr(double x) { return x * x; }
int main() {
const int test = 5;
constexpr double result = square_cstxpr((double)test);
}
However, if the type of test is changed from const int to const double, g++ gives the following error: the value of 'test' is not usable in a constant expression.
See the code and output of g++ here: http://ift.tt/2wHLCkD
Could somebody explain that behavior?
Aucun commentaire:
Enregistrer un commentaire