On Feb 24, 2006, at 8:55 AM, Richard Guenther wrote:
On 2/24/06, Perry Smith <[EMAIL PROTECTED]> wrote:I have asked this question before -- maybe to the gcc-help list but I'm still unclear. The problem is this: struct foo { int a; int b; int c; }; static const int foo::*j = &foo::c; // accepted class dog { static const int foo::*k = &foo::c; // error }; 5.19 (constant expressions) paragraph 2, the last item in the 1998 C+ + spec says " -- a pointer to member constant expression." That appears to be defined as: '&' qualified-id (5.19 paragraph 6). So is the line in error legal C++ or not?No. t.C:10: error: 'foo::c' cannot appear in a constant-expression t.C:10: error: `&' cannot appear in a constant-expression t.C:10: error: invalid in-class initialization of static data member of non-integral type 'const int foo::*'
But '&' can occur in a constant-expression and 'foo::c' is a unique-id which can also appear in a constant expression (see 5.19). And as far as the static const data member, 9.4.2 paragraph 4 says: If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression (5.19). In that case, the member can appear in integral constant expressions within its scope. The member shall still be defined in a namespace scope if it is used in the program and the namespace scope definition shall not con- tain an initializer. Note that 5.19 states that '&foo::c' is an integral constant expression. So I draw the conclusion that k is a const integral type (but I have not seen a place in the spec that actually says that a pointer to member is an integral expression but what else could it be? Sorry to be a pest but I just don't see why my construct is excluded. Thank you for your time and patience, Perry
