Title
Do elaborated type specifiers in templates inject into enclosing namespace scope?
Status
cd1
Section
6.4.2 [basic.scope.pdecl]
Submitter
Daveed Vandevoorde

Created on 2003-09-02.00:00:00 last changed 34 months ago

Messages

Date: 2004-03-15.00:00:00

[Voted into WP at March 2004 meeting.]

Date: 2022-02-18.07:47:23

Proposed resolution:

In 6.4.2 [basic.scope.pdecl] change the second bullet of paragraph 5 as follows:

for an elaborated-type-specifier of the form
   class-key identifier
if the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of a function defined in namespace scope, the identifier is declared as a class-name in the namespace that contains the declaration; otherwise, except as a friend declaration, the identifier is declared in the smallest non-class, non-function-prototype scope that contains the declaration. [Note: These rules also apply within templates.] [Note: ...]
Date: 2003-10-15.00:00:00

Notes from October 2003 meeting:

There was consensus that example 1 should be allowed. (Compilers already parse declarations in templates; even MSVC++ 6.0 accepts this case.) The vote was 7-2.

Example 2, on the other hand, is wrong; the union name goes into a block scope anyway.

Date: 2004-09-10.00:00:00

Consider the following translation unit:

  template<class T> struct S {
    void f(union U*);  // (1)
  };
  template<class T> void S<T>::f(union U*) {}  // (2)
  U *p;  // (3)

Does (1) introduce U as a visible name in the surrounding namespace scope?

If not, then (2) could presumably be an error since the "union U" in that definition does not find the same type as the declaration (1).

If yes, then (3) is OK too. However, we have gone through much trouble to allow template implementations that do not pre-parse the template definitions, but requiring (1) to be visible would change that.

A slightly different case is the following:

  template<typename> void f() { union U *p; }
  U *q;  // Should this be valid?
History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6688
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2004-04-09 00:00:00adminsetmessages: + msg999
2004-04-09 00:00:00adminsetstatus: ready -> wp
2003-11-15 00:00:00adminsetmessages: + msg905
2003-11-15 00:00:00adminsetstatus: open -> ready
2003-09-02 00:00:00admincreate