Topic: Use of typedef before redefinition in struct
Author: algrant@myrealbox.com (Al Grant)
Date: Mon, 30 Sep 2002 12:40:35 +0000 (UTC) Raw View
gdr@integrable-solutions.net (Gabriel Dos Reis) wrote in message news:<m3u1khxj10.fsf@soliton.integrable-solutions.net>...
> algrant@myrealbox.com (Al Grant) writes:
>
> | Consider the following:
> |
> | #1: typedef int T; struct X { typedef T T; };
> | #2: typedef int T; struct X { typedef T U; typedef T T; };
> | #3: typedef int T; struct X { typedef T U; typedef int T; };
> | #4: typedef int T; struct X { typedef T U; typedef char T; };
>
> All those constructs are ill-formed (but no diagnostic is required).
> 3.3.6/2:
Thanks, that seems clear enough. There is even an example of #1.
Since GNU invoked 3.4.1/7 that was the place I looked.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: algrant@myrealbox.com (Al Grant)
Date: Sun, 22 Sep 2002 20:36:50 +0000 (UTC) Raw View
Consider the following:
#1: typedef int T; struct X { typedef T T; };
#2: typedef int T; struct X { typedef T U; typedef T T; };
#3: typedef int T; struct X { typedef T U; typedef int T; };
#4: typedef int T; struct X { typedef T U; typedef char T; };
The issue is whether 3.4.1/7 forbids the use of T before, or in,
the definition of S::T. VC++ and Comeau accept them all.
g++ 3.1 faults them all. HP aCC accepts #1 only.
The applicable text of 3.4.1/7 is
A name used in the definition of a class X outside of a member
function body or nested class definition [footnote: this refers
to unqualified names following the class name] shall be declared
in one of the following ways
- before its use in class X
- ... various other nested class and namespace situations
The name T is used in the definition of X and it is declared
before its use in class X. So that should be ok. GNU must be
interpreting the text to mean that if T is declared in X at all,
it must be declared before any unqualified use in X, but I can't
see that's justified. All 3.4.1/7 seems to be saying is that
lookup in class definitions (apart from member function bodies
and nested classes) works in the usual C/C++ way, i.e.
typedef int T; struct X { typedef T U; typedef char T; };
works like
typedef int T; void f() { typedef T U; typedef char T; }
So who's right - g++ or Comeau?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Mon, 23 Sep 2002 14:37:37 +0000 (UTC) Raw View
algrant@myrealbox.com (Al Grant) writes:
| Consider the following:
|
| #1: typedef int T; struct X { typedef T T; };
| #2: typedef int T; struct X { typedef T U; typedef T T; };
| #3: typedef int T; struct X { typedef T U; typedef int T; };
| #4: typedef int T; struct X { typedef T U; typedef char T; };
All those constructs are ill-formed (but no diagnostic is required).
3.3.6/2:
A name N used in a class S shall refer to the same declaration in
its context and when re-evaluated in the completed scope of S. No
diagnostic is required for a violation of this rule.
[...]
| So who's right - g++ or Comeau?
Both. Just avoid such confusing constructs.
I far more prefer a diagnostic. YMMV.
--
Gabriel Dos Reis gdr@integrable-solutions.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]