 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bill Clarke Guest
|
Posted: Mon Sep 13, 2004 9:53 am Post subject: repeated typedefs |
|
|
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 ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Mon Sep 13, 2004 12:17 pm Post subject: Re: repeated typedefs |
|
|
Bill Clarke wrote:
| Quote: | 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 ]
|
|
| Back to top |
|
 |
Greg Comeau Guest
|
Posted: Tue Sep 14, 2004 3:18 am Post subject: Re: repeated typedefs |
|
|
In article <b2dfb7d8.0409130012.1dde5ab7 (AT) posting (DOT) google.com>,
Bill Clarke <llib (AT) computer (DOT) org> wrote:
| Quote: | 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..
| Quote: | 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 ]
|
|
| Back to top |
|
 |
Bill Clarke Guest
|
Posted: Tue Sep 14, 2004 4:06 am Post subject: Re: repeated typedefs |
|
|
Ben Hutchings wrote, On 13/09/04 22:17:
| Quote: | 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 ]
|
|
| Back to top |
|
 |
Greg Comeau Guest
|
Posted: Tue Sep 14, 2004 4:22 pm Post subject: Re: repeated typedefs |
|
|
In article <b2dfb7d8.0409131832.b7726bd (AT) posting (DOT) google.com>,
Bill Clarke <llib (AT) computer (DOT) org> wrote:
| Quote: | However, 7.1.3/2 is so unequivocal that perhaps there should be a note
pointing to 9.2/1 regarding class scopes.
|
Probably.
| Quote: | 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 ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|