C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

repeated typedefs

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Bill Clarke
Guest





PostPosted: Mon Sep 13, 2004 9:53 am    Post subject: repeated typedefs Reply with 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).

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





PostPosted: Mon Sep 13, 2004 12:17 pm    Post subject: Re: repeated typedefs Reply with quote



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





PostPosted: Tue Sep 14, 2004 3:18 am    Post subject: Re: repeated typedefs Reply with quote



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





PostPosted: Tue Sep 14, 2004 4:06 am    Post subject: Re: repeated typedefs Reply with quote

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





PostPosted: Tue Sep 14, 2004 4:22 pm    Post subject: Re: repeated typedefs Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.