Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 957181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:39:37+00:00 2026-05-16T00:39:37+00:00

This is an academic question. In the report for GCC bug 38764 , there

  • 0

This is an academic question.

In the report for GCC bug 38764, there are the following examples:

template < class T > struct A {};
typedef A< float > A; // Accepted by Comeau, but not GCC
typedef ::A< float > A; // Accepted by GCC but not Comeau

I see why the code may be invalid, but I have trouble with one of the comments:

This code is invalid but the standard says for this case no diagnostic is required so both compilers are correct according to the standard.

Why is the code that is “invalid” accepted by the standard as valid? What does the standard say about this case in particular (template + type with the same name) and, in general, about namespaces for various entities (types, templates, functions, variables)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:39:38+00:00Added an answer on May 16, 2026 at 12:39 am

    When the standard says “no diagnostic required”, that means that the compiler does not have to produce an error or warning about the invalid code, but that the code’s behavior is still undefined according to the standard and so it won’t necessarily have predictable results. This is intended to make things easier on compiler-writers so that they are not obligated to detect relatively rare or particularly troublesome-to-detect sorts of programmer errors.

    However, when a rule with “no diagnostic required” is violated, the compiler is not prohibited from detecting the invalid code and producing an error as a courtesy to the user. So in the example given, gcc is producing a courtesy diagnostic for one particular sort of invalid code, and Comeau is producing a courtesy diagnostic for a similar sort of invalid code. But neither diagnostic is required, so in neither case is the other compiler in violation of the standard by not producing an error message. The behavior of the code remains undefined in any case.

    Several relevant standards quotations regarding class names and template names:

    3.4/1

    The name lookup rules apply uniformly
    to all names (including typedef-names
    (7.1.3), namespace-names (7.3) and
    class-names (9.1)) wherever the
    grammar allows such names in the
    context discussed by a particular
    rule. Name lookup associates the use
    of a name with a declaration (3.1) of
    that name. Name lookup shall find an
    unambiguous declaration for the name
    (see 10.2). […]

    7.1.3/3

    In a given scope, a typedef specifier
    shall not be used to redefine the name
    of any type declared in that scope to
    refer to a different type. [Example:

    class complex { /* ... */ }; 
    typedef int complex; // error: redefinition
    

    —end example] Similarly, in a given
    scope, a class or enumeration shall
    not be declared with the same name as
    a typedef-name that is declared in
    that scope and refers to a type other
    than the class or enumeration itself. […]

    9.1/2

    A class definition introduces the
    class name into the scope where it is
    defined and hides any class, object,
    function, or other declaration of that
    name in an enclosing scope (3.3). If a
    class name is declared in a scope
    where an object, function, or
    enumerator of the same name is also
    declared, then when both declarations
    are in scope, the class can be
    referred to only using an
    elaborated-type-specifier (3.4.4).

    14/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.

    14.5.4/1

    A primary class template declaration
    is one in which the class template
    name is an identifier. A template
    declaration in which the class
    template name is a template-id, is a
    partial specialization of the class
    template named in the template-id. A
    partial specialization of a class
    template provides an alternative
    definition of the template that is
    used instead of the primary definition
    when the arguments in a specialization
    match those given in the partial
    specialization (14.5.4.1). […]

    So, in summary:

    • typedefs cannot change the meaning of an existing type
    • class names can conflict with certain sorts of names, but not other class names
    • template class names do not include the template parameter, and cannot conflict with anything, even things that normal class names are allowed to conflict with
    • template specializations are considered to have the same template-id (name) as their corresponding generalized template, but they are (obviously) not the same type.

    So there’s a conflict in both directions here. The template name is not allowed to conflict with anything, and the typedef is not allowed to change A from a template class type to a specialization of a template class type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of an academic inquiry than a practical question. Are there any
This is more of an academic question about performance than a realistic 'what should
This is a pretty academic question. I'm wondering how the browser is implemented as
This is a purely academic question, but what's the difference between using == and
This is kind of an academic question, so feel free to exit now. I've
This may seem to be an academic question, but still I would be very
Somewhat of an academic question, but I ran into this while writing some unit
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This is a bit of a long shot, but if anyone can figure it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.