mardi 1 mars 2016

Unable to initialize constexpr

When compiling this code with clang (version 3.0-6ubuntu3):

constexpr int foo(const int n) {
    return n + 1;
}

int main(void) {
    constexpr int x = 5 * 4 + 12 + 8;
    constexpr int y = foo(x);
    return 0;
}

Using this command:

clang -std=c++11 -c constexprExample.cpp

I get following error:

error: constexpr variable 'y' must be initialized by a constant expression

Is it something wrong with code or the compiler?

Aucun commentaire:

Enregistrer un commentaire