问题
According to [basic.lookup.unqual]/8 from N4140 the following snippet should compile. But it doesn't in clang, gcc and vs2013.
struct C {
void f(I) {}
using I = int;
};
[basic.lookup.unqual]/8 (emphases are mine):
For the members of a class
X
, a name used in a member function body, in a default argument, in an exception-specification, in the brace-or-equal-initializer of a non-static data member (9.2), or in the definition of a class member outside of the definition ofX
, following the member’s declarator-id31, shall be declared in one of the following ways:
- before its use in the block in which it is used or in an enclosing block (6.3), or
- shall be a member of class
X
or be a member of a base class ofX
(10.2), or- ...
31) That is, an unqualified name that occurs, for instance, in a type in the parameter-declaration-clause or in the exceptions-pecification.
回答1:
The way you are using it does not fall under any of the conditions in [basic.lookup.unqual]/8, it is not used:
- in a member function body
- in a default argument
- in an exception-specification
- in the brace-or-equal-initializer of a non-static data member
and it does not fall under this case either:
definition of a class member outside of the definition of X
the following example shows some cases that do follow those rules:
struct C {
int y = I() ; // brace-or-equal-initializer of non-static data member
void f(int x = I()) // default argument
noexcept(sizeof(I)<4) // exception-specification
{
I i = x ; // member function body
}
using I = int;
};
回答2:
[…] or in the definition of a class member outside of the definition of
X
, following the member’s declarator-id
I.e. the following is valid
struct C {
using I = int;
void f(I);
};
void C::f(I) {}
来源:https://stackoverflow.com/questions/31457627/according-to-my-interpretation-of-3-4-1-8-this-code-should-compile-what-am-i-m