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?
The decltype type specifier yields the type of a specified expression. The decltype type specifier, together with the auto keyword, is useful primarily to developers who write template libraries. Use auto and decltype to declare a template function whose return type depends on the types of its template arguments.
decltype is a compile time evaluation (like sizeof ), and so can only use the static type.
The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated with a type (such as int and double) too. Naming Convention of Pointers: Include a "p" or "ptr" as prefix or suffix, e.g., iPtr, numberPtr, pNumber, pStudent.
The pointer to member operators . * and ->* are used to bind a pointer to a member of a specific class object. Because the precedence of () (function call operator) is higher than . * and ->* , you must use parentheses to call the function pointed to by ptf .
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::
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With