dyp
unread,Dec 16, 2014, 3:30:02 PM12/16/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to std-dis...@isocpp.org
Are constexpr non-static member functions allowed as members of
non-literal types?
The proposal N3652 "Relaxing constraints on constexpr functions" still
contains a restriction in [dcl.constexpr] (7.1.5)/8:
"The class of which <strike>that</strike> a constexpr function is a
member shall be a literal type (3.9)."
However, the proposed resolution of CWG 1684 removed that sentence
entirely. The rationale given is:
"The previous version of this wording made clear that the restriction
on the class type applied only to non-static member functions;
consequently, the new formulation has inadvertently banned static
constexpr member functions of non-literal classes."
It is not clear to me if allowing constexpr non-static member
functions for non-literal classes is intended to be allowed. I cannot
find any other restriction in the Standard drafts. Furthermore, both
clang++ and g++ tip of trunk refuse them:
#include <string>
struct X {
std::string s;
constexpr int foo() { return 42; }
};
int main() {}
clang++: error: non-literal type 'X' cannot have constexpr members
g++: error: enclosing class of constexpr non-static member function
‘int X::foo()’ is not a literal type
Are they allowed? If not, where is it specified that they're illegal?
Thanks and kind regards,
dyp