Reputation: 16724
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);
}
Upvotes: 5
Views: 2339
Reputation: 7187
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 { ... }
Upvotes: 15
Reputation: 14158
Complete testcase:
struct S {
constexpr int getSize();
};
Diagnostic:
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
Note in particular the bottom line of the output. That's called a 'fix-it hint' and shows you the text you need to insert (and where to insert it) to fix the problem.
(In this case, the text starts with a leading space, making it slightly less clear that it should be inserted before the semicolon, not afterwards.)
Upvotes: 1