standard conform typedef?

Discussion in 'C++' started by stip, Apr 21, 2011.

  1. stip

    stip Guest

    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
     
    stip, Apr 21, 2011
    #1
    1. Advertising

  2. stip

    Qi Guest

    On 2011-4-21 16:31, stip wrote:

    > 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."


    --
    WQ
     
    Qi, Apr 21, 2011
    #2
    1. Advertising

  3. stip wrote:

    > 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).
     
    Johannes Schaub, Apr 21, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gaurav
    Replies:
    0
    Views:
    16,138
    Gaurav
    Nov 7, 2003
  2. andy
    Replies:
    0
    Views:
    4,129
  3. X l e c t r i c

    Can Division Width Conform To Content

    X l e c t r i c, Feb 16, 2006, in forum: HTML
    Replies:
    3
    Views:
    659
    kchayka
    Feb 16, 2006
  4. Michel T.
    Replies:
    14
    Views:
    898
    John Ersatznom
    Jan 18, 2007
  5. Fumeur

    Is this program standard conform?

    Fumeur, Jan 21, 2008, in forum: C Programming
    Replies:
    25
    Views:
    725
    Keith Thompson
    Jan 22, 2008
Loading...

Share This Page