Thread overview
[bug] Compiler flags multiple identical member type definitions as error; should be warning
Dec 10, 2005
Matthew
Dec 10, 2005
Walter Bright
Dec 10, 2005
Matthew
Dec 10, 2005
Walter Bright
Dec 11, 2005
Matthew
Dec 11, 2005
Walter Bright
Dec 11, 2005
Matthew
Dec 11, 2005
Walter Bright
December 10, 2005


December 10, 2005
It's supposed to be an error.

BTW, the C++ standard does not require any warnings.


December 10, 2005
"Walter Bright" <newshound@digitalmars.com> wrote in message news:dndu5o$2t25$1@digitaldaemon.com...
> It's supposed to be an error.

Well, I did leave the gate in my mind open for the possibility of being wrong (because I couldn't muster the effort to trawl the standard). Which clause relates?

> BTW, the C++ standard does not require any warnings.

Indeed. ;-)



December 10, 2005
"Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dne1ba$2vjk$2@digitaldaemon.com...
>
> "Walter Bright" <newshound@digitalmars.com> wrote in message news:dndu5o$2t25$1@digitaldaemon.com...
> > It's supposed to be an error.
>
> Well, I did leave the gate in my mind open for the possibility of being wrong (because I couldn't muster the effort to trawl the standard). Which clause relates?

I don't remember, just that the allowance for multiple declarations of the same name is for global names.


December 11, 2005
"Walter Bright" <newshound@digitalmars.com> wrote in message news:dnfnep$2vjr$1@digitaldaemon.com...
>
> "Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dne1ba$2vjk$2@digitaldaemon.com...
> >
> > "Walter Bright" <newshound@digitalmars.com> wrote in message news:dndu5o$2t25$1@digitaldaemon.com...
> > > It's supposed to be an error.
> >
> > Well, I did leave the gate in my mind open for the possibility of being wrong (because I couldn't muster the effort to trawl the standard).
Which
> > clause relates?
>
> I don't remember, just that the allowance for multiple declarations of the same name is for global names.

Sorry, buddy. I think you're wrong.

Clause 7.1.3;2 states "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".

There's no mention of this rule being applicable to global or namespace scope only.



December 11, 2005
"Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dnfsi9$2pn$1@digitaldaemon.com...
>
> "Walter Bright" <newshound@digitalmars.com> wrote in message news:dnfnep$2vjr$1@digitaldaemon.com...
> >
> > "Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dne1ba$2vjk$2@digitaldaemon.com...
> > >
> > > "Walter Bright" <newshound@digitalmars.com> wrote in message news:dndu5o$2t25$1@digitaldaemon.com...
> > > > It's supposed to be an error.
> > >
> > > Well, I did leave the gate in my mind open for the possibility of
being
> > > wrong (because I couldn't muster the effort to trawl the standard).
> Which
> > > clause relates?
> >
> > I don't remember, just that the allowance for multiple declarations of
the
> > same name is for global names.
>
> Sorry, buddy. I think you're wrong.
>
> Clause 7.1.3;2 states "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".
>
> There's no mention of this rule being applicable to global or namespace scope only.

C++ 9.2-1 sez: "A member shall not be declared twice in the member-specification, except that a nested class or member class template can be declared and then later defined." 9.2-1 also specifically says that typedef's are considered members of a class.

Check!


December 11, 2005
"Walter Bright" <newshound@digitalmars.com> wrote in message news:dngccp$gv6$1@digitaldaemon.com...
>
> "Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dnfsi9$2pn$1@digitaldaemon.com...
> >
> > "Walter Bright" <newshound@digitalmars.com> wrote in message news:dnfnep$2vjr$1@digitaldaemon.com...
> > >
> > > "Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dne1ba$2vjk$2@digitaldaemon.com...
> > > >
> > > > "Walter Bright" <newshound@digitalmars.com> wrote in message news:dndu5o$2t25$1@digitaldaemon.com...
> > > > > It's supposed to be an error.
> > > >
> > > > Well, I did leave the gate in my mind open for the possibility of
> being
> > > > wrong (because I couldn't muster the effort to trawl the standard).
> > Which
> > > > clause relates?
> > >
> > > I don't remember, just that the allowance for multiple declarations of
> the
> > > same name is for global names.
> >
> > Sorry, buddy. I think you're wrong.
> >
> > Clause 7.1.3;2 states "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".
> >
> > There's no mention of this rule being applicable to global or namespace scope only.
>
> C++ 9.2-1 sez: "A member shall not be declared twice in the member-specification, except that a nested class or member class template can be declared and then later defined." 9.2-1 also specifically says that typedef's are considered members of a class.
>
> Check!

I'm happy to topple the king on this one. :-)

I think it could still be argued either way, but I find 9.2;1 to be more specific than 7.1.3;2, and common sense should incline us to go for the more specific.

Seems like writing a standard is probably even harder than reading one. Something to bear in mind ...



December 11, 2005
"Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dngf7c$j3h$1@digitaldaemon.com...
> I think it could still be argued either way, but I find 9.2;1 to be more specific than 7.1.3;2, and common sense should incline us to go for the
more
> specific.

I think it's nothing more than a contradiction in the standard that should be corrected with the next one. If one intends to write conforming code, one should take the most restrictive as the rule. A compiler implementer should implement the most expansive rule. I'm inclined to leave this one as it is in DMC++, however, because other C++ compilers disallow it, and because I can't think of a need to allow it.

For the global case, however, it is a needed feature as a kludge to make up
for the lack of true modules in C++. It enables things like:
    typedef unsigned short wchar_t;
to appear in multiple .h files without a complex macro system that allows
only one of them to be 'active.'

> Seems like writing a standard is probably even harder than reading one. Something to bear in mind ...

Yup. It's as difficult to write it to be bug-free as writing the software itself.