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

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

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

Where to add constso? const constexpr size_t getSize() {give another warning:

the 'const' type of the classifier with the inverse type has no effect

the code:

constexpr size_t getSize()
{
    return sizeof(header);
}
+4
source share
2 answers

I believe that it tells you that a member function cannot be called in an object constwith C ++ 1y.

const getSize(), const:

constexpr size_t getsize() const { ... }
+14

:

struct S {
  constexpr int getSize();
};

:

tmp.cc:2:17: warning: 'constexpr' non-static member function will not be
        implicitly 'const' in C++1y; add 'const' to avoid a change in
        behavior [-Wconstexpr-not-const]
  constexpr int getSize();
                ^
                          const

, , . "fix-it hint" , ( ), .

( , , , .)

+1

Source: https://habr.com/ru/post/1536893/


All Articles