Search code examples
c++constantsclangconstexpr

'constexpr' non-static member function will not be implicitly 'const' in C++1y; add 'const' to avoid a change in behavior


clang++ give the following warning(see code below):

'constexpr' non-static member function will not be implicitly 'const' in C++1y; add 'const' to avoid a change in behavior

Where should the const be add so? const constexpr size_t getSize() { give another warning:

'const' type qualifier on return type has no effect

code:

constexpr size_t getSize()
{
    return sizeof(header);
}

Solution

  • I believe it's telling you that the member function can't be called on a const object as of C++1y.

    Add const after getSize() to make it a const member function:

    constexpr size_t getsize() const { ... }