vendredi 20 mars 2020

Unable to assign constexpr pointer to address of constexpr variable [duplicate]

I was learning about constexpr and trying to compile this code on on Mac OSX, with LLVM version 10.0.1 (clang-1001.0.46.4):

int main()
{
    constexpr int a = 10;
    constexpr const int *p = &a;
    return 0;
}

However, this code throws me an error:

constexpr.cpp:4:26: error: constexpr variable 'p' must be initialized by a constant expression

But p is being initialized by a constant expression. What seems to be the error?

Aucun commentaire:

Enregistrer un commentaire