Topic: repeated typedefs
Author: comeau@panix.com (Greg Comeau)
Date: Tue, 14 Sep 2004 03:18:16 GMT Raw View
In article <b2dfb7d8.0409130012.1dde5ab7@posting.google.com>,
Bill Clarke <llib@computer.org> wrote:
>My reading of the standard is (and g++ 3.4.0 agrees with me) that the
>following is entirely legal:
>
>"""
>typedef int Int;
>typedef int Int;
>
>namespace B {
> typedef int IntB;
> typedef int IntB;
>}
>
>class A {
> void foo() {
> typedef int Intfoo;
> typedef int Intfoo;
> }
> typedef int IntA;
> typedef int IntA;
>};
>"""
>
>However, Comeau's online compiler rejects the redefinition of IntA
>(coincidently, so does Sun's compiler Sun Studio 9, but it's no fine
>example of C++ standard compliance).
Well, AFAICrecall, this rule's been the same for a very long time, so..
>C++ standard 7.1.3 (dcl.typedef) paragraph 2 seems to apply here.
>"""
>2 In a given scope, a typedef specifier can be used to redefine the name
> of any type declared in that scope to refer to the type to which it
> already refers. [Example:
> typedef struct s { /* ... */ } s;
> typedef int I;
> typedef int I;
> typedef I I;
> --end example]
>"""
>
>Is there anything else that applies here?
9.2p1: "...Members of a class are ... nested types, and ....
..Nested types are... arbitrary types declared as members by
use of a typedef declaration .... A member shall not be declared
twice in the member-specification...."
--
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
---
[ 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: llib@computer.org (Bill Clarke)
Date: Tue, 14 Sep 2004 04:06:08 GMT Raw View
Ben Hutchings wrote, On 13/09/04 22:17:
> Bill Clarke wrote:
[...]
>>class A {
[...]
>> typedef int IntA;
>> typedef int IntA;
>>};
>>"""
[...]
>>C++ standard 7.1.3 (dcl.typedef) paragraph 2 seems to apply here.
>>"""
>>2 In a given scope, a typedef specifier can be used to redefine the
name
>> of any type declared in that scope to refer to the type to which
it
>> already refers. [Example:
>> typedef struct s { /* ... */ } s;
>> typedef int I;
>> typedef int I;
>> typedef I I;
>> --end example]
>>"""
>>
>>Is there anything else that applies here?
>
>
> Class scopes are special. From 9.2 paragraph 1:
>
> "A member shall not be be declared twice in the /member-
> specification/, except that a nested class or member class
> template can be declared and then later defined."
>
Okay, I'll accept that (bug report submitted to gcc: PR 17473).
However, 7.1.3/2 is so unequivocal that perhaps there should be a note
pointing to 9.2/1 regarding class scopes.
In addition, it seems plain weird to have an exception for
class-scopes, when other scopes that have equally no reason for
allowing redefinitions are allowed (namely, function scopes).
cheers,
/lib
---
[ 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: comeau@panix.com (Greg Comeau)
Date: Tue, 14 Sep 2004 10:22:26 CST Raw View
In article <b2dfb7d8.0409131832.b7726bd@posting.google.com>,
Bill Clarke <llib@computer.org> wrote:
>However, 7.1.3/2 is so unequivocal that perhaps there should be a note
>pointing to 9.2/1 regarding class scopes.
Probably.
>In addition, it seems plain weird to have an exception for
>class-scopes, when other scopes that have equally no reason for
>allowing redefinitions are allowed (namely, function scopes).
C doesn't allow (at least some of) the other cases, so in an odd twist,
it's the other cases which became the (allowed) exceptions.
--
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
---
[ 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: llib@computer.org (Bill Clarke)
Date: Mon, 13 Sep 2004 09:53:55 GMT Raw View
My reading of the standard is (and g++ 3.4.0 agrees with me) that the
following is entirely legal:
"""
typedef int Int;
typedef int Int;
namespace B {
typedef int IntB;
typedef int IntB;
}
class A {
void foo() {
typedef int Intfoo;
typedef int Intfoo;
}
typedef int IntA;
typedef int IntA;
};
"""
However, Comeau's online compiler rejects the redefinition of IntA
(coincidently, so does Sun's compiler Sun Studio 9, but it's no fine
example of C++ standard compliance).
C++ standard 7.1.3 (dcl.typedef) paragraph 2 seems to apply here.
"""
2 In a given scope, a typedef specifier can be used to redefine the name
of any type declared in that scope to refer to the type to which it
already refers. [Example:
typedef struct s { /* ... */ } s;
typedef int I;
typedef int I;
typedef I I;
--end example]
"""
Is there anything else that applies here?
cheers,
/lib
---
[ 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: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Date: Mon, 13 Sep 2004 12:17:19 GMT Raw View
Bill Clarke wrote:
> My reading of the standard is (and g++ 3.4.0 agrees with me) that the
> following is entirely legal:
<snip>
> class A {
> void foo() {
> typedef int Intfoo;
> typedef int Intfoo;
> }
> typedef int IntA;
> typedef int IntA;
> };
> """
>
> However, Comeau's online compiler rejects the redefinition of IntA
> (coincidently, so does Sun's compiler Sun Studio 9, but it's no fine
> example of C++ standard compliance).
>
> C++ standard 7.1.3 (dcl.typedef) paragraph 2 seems to apply here.
> """
> 2 In a given scope, a typedef specifier can be used to redefine the name
> of any type declared in that scope to refer to the type to which it
> already refers. [Example:
> typedef struct s { /* ... */ } s;
> typedef int I;
> typedef int I;
> typedef I I;
> --end example]
> """
>
> Is there anything else that applies here?
Class scopes are special. From 9.2 paragraph 1:
"A member shall not be be declared twice in the /member-
specification/, except that a nested class or member class
template can be declared and then later defined."
--
Ben Hutchings
We get into the habit of living before acquiring the habit of thinking.
- Albert Camus
---
[ 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 ]