Imagine for some strange reason I write this:
int main()
{
struct S
{
int i;
} var;
int decltype(var)::* pint = &decltype(var)::i;
}
GCC seems to compile it fine although Clang fails with some indeterminate syntax-related error message.
So what does the holy ISO paper says about this - is this valid or not?
This is actually a known bug in Clang.
The code is valid.
N4140 [dcl.mptr]/1:
In a declaration
T D
whereD
has the formnested-name-specifier
*
attribute-specifier-seqopt cv-qualifier-seqoptD1
and the nested-name-specifier denotes a class, and the type of the identifier in the declaration
T D1
is “derived-declarator-type-listT
”, then the type of the identifier ofD
is “derived-declarator-type-list cv-qualifier-seq pointer to member of class nested-name-specifier of typeT
”. The optional attribute-specifier-seq (7.6.1) appertains to the pointer-to-member.
In this definition we are interested in nested-name-specifier, and it's defined at [expr.prim.general]/8 as (emphasis mine):
nested-name-specifier:
::
type-name::
namespace-name::
decltype-specifier::
nested-name-specifier identifier::
nested-name-specifiertemplate
opt simple-template-id::