standard conform typedef?

S

stip

template <typename T>
struct A
{
};

template <typename T>
struct B
{
typedef A<T> A;
};

int
main()
{
return 0;
}

Look at the reuse of "A".
IMHO this is legal. But gcc rejects it:
Declaration of »typedef struct A<T> B<T>::A«

If it is not legal, can someone point me to the corresponding part of
the standard?

Best,
Alex
 
Q

Qi

Look at the reuse of "A".
IMHO this is legal. But gcc rejects it:
Declaration of »typedef struct A<T> B<T>::A«

If it is not legal, can someone point me to the corresponding part of
the standard?

Chapter 14, item 5,

"A class template shall not have the same name as any other template,
class, function, object, enumeration,
enumerator, namespace, or type in the same scope (3.3), except as
specified in (14.5.4). Except that a function
template can be overloaded either by (non-template) functions with the
same name or by other function
templates with the same name (14.8.3), a template name declared in
namespace scope or in class scope
shall be unique in that scope."
 
J

Johannes Schaub

stip said:
template <typename T>
struct A
{
};

template <typename T>
struct B
{
typedef A<T> A;
};

int
main()
{
return 0;
}

Look at the reuse of "A".
IMHO this is legal. But gcc rejects it:
Declaration of »typedef struct A<T> B<T>::A«

If it is not legal, can someone point me to the corresponding part of
the standard?

This is ill-formed with no diagnostic required. Refer to
3.3.6[basic.scope.class]p1, subparagraph 2).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top