Draft N3337 of the C++11 standard states in
[namespace.udecl]
A using-declaration introduces a name into the declarative region in which the
using-declaration appears.
Every
using-declaration is a declaration and a member-declaration and so can be used in a
class definition.
In a
using-declaration used as a member-declaration, the nested-name-specifier shall name a
base class of the
class being
defined.
This is
generally used to make a protected typedef within a base-class public in the derived
class, as in the following example, which compiles successfully in the latest version of
Clang:
struct
A
{
protected:
typedef int
Type;
};
struct B : A
{
using A::Type;
};
B::Type
x;
The
using-declaration can refer to a template class. This
compiles:
struct
A
{
protected:
template
struct Type
{
};
};
struct B : A
{
using A::Type;
};
B::Type
x;
It's also possible
to refer to a template in a dependent base-class. The following compiles successfully
(with the typedef
commented.)
template T>
struct A
{
protected:
template
struct Type
{
};
};
template T>
struct B : A
{
using /* typename */
A::Type; // A is dependent, typename required?
// typedef
Type IntType; // error: unknown type name
'Type'
};
B::Type
x;
Uncommenting
the typename
causes an error when instantiating
B
: "error: 'typename' keyword used on a
non-type".
Uncommenting the typedef causes an
error when parsing B
before its first instantiation. I'm
guessing this is because the compiler does not treat Type
as a
dependent type-name.
The last paragraph of
[namespace.udecl]
suggests that using-declarations may specify
dependent names, and that the typename
keyword must be used in
order to disambiguate further usage of the name
introduced:
If a
using-declaration uses the keyword typename and specifies a dependent name (14.6.2), the
name introduced
by the using-declaration is treated as a
typedef-name
My
reading of [temp.dep]
suggests that
A
is a dependent name. It follows logically that
the name introduced by the using-declaration should also be dependent, but
[temp.dep]
does not explicitly mention the case of a dependent
using-declaration. Am I missing something?
No comments:
Post a Comment