Topic: Defect Report: Qualified name lookup applied before template instantiation ?
Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: 30 Aug 2002 19:05:08 GMT Raw View
"Raoul Gough" <RaoulGough@yahoo.co.uk> wrote...
> "Code Beaver" <pagey@pagey.info> wrote in message
> news:BTh99.4642$_7.469568@twister.socal.rr.com...
> >
> > [moderator's note: Forwarded to C++ Committee. -sdc]
> >
> > Section 14.6[temp.res] paragraph 4 uses the following example to
> show that
> > qualified name lookup described in Section 3.4.3[basic.lookup.qual]
> applies
> > even in the presence of "typename":
> >
> > struct A {
> > struct X { } ;
> > int X ;
> > } ;
> > template<class T> void f(T t) {
> > typename T::X x ; // ill-formed: finds the data member X
> > // not the member type X
> > }
> [snip]
>
> I'm confused. I recently had to look up the rules for a struct similar
> to A in the example, and eventually found 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."
>
> Wouldn't this rule make the struct definition ill-formed in the first
> place, and remove any potential for ambiguity in the template?
No. When struct X is defined, the name 'X' is not "used", but
"introduced" (or "defined") as a type-id. When 'X' is declared
on the next line, 'X' is "introduced" as an [sub-]object-id.
No conflict. "int X" hides "struct X" (see 3.3.7, paragraph 2).
Victor
--
Please remove capital A's from my address when replying by mail
---
[ 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: "Raoul Gough" <RaoulGough@yahoo.co.uk>
Date: Fri, 30 Aug 2002 16:57:48 CST Raw View
"Victor Bazarov" <vAbazarov@dAnai.com> wrote in message
news:umvf1jtickji5e@corp.supernews.com...
> "Raoul Gough" <RaoulGough@yahoo.co.uk> wrote...
> > "Code Beaver" <pagey@pagey.info> wrote in message
> > news:BTh99.4642$_7.469568@twister.socal.rr.com...
> > > struct A {
> > > struct X { } ;
> > > int X ;
> > > } ;
> > [snip]
> >
> > I'm confused. I recently had to look up the rules for a struct
similar
> > to A in the example, and eventually found 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."
> >
> > Wouldn't this rule make the struct definition ill-formed in the
first
> > place, and remove any potential for ambiguity in the template?
>
>
> No. When struct X is defined, the name 'X' is not "used", but
> "introduced" (or "defined") as a type-id. When 'X' is declared
> on the next line, 'X' is "introduced" as an [sub-]object-id.
> No conflict. "int X" hides "struct X" (see 3.3.7, paragraph 2).
OK, I missed the distinction between "using" and "introducing". Just
to confirm my understanding, the following would also be valid:
typedef int foo;
struct bar {
foo foo; // "introduce" member foo of type ::foo
};
I ask because gcc 3.1 rejects it:
$ f:/mingw/bin/g++ -c typename_reuse.cc
typename_reuse.cc:4: declaration of `foo bar::foo'
typename_reuse.cc:1: changes meaning of `foo' from `typedef int foo'
I reported this in relation to an already opened gcc bug and was told
that the simple code example was ill-formed. I did some reading and
assumed that the section I quoted was the reason for this. So it
really is a gcc bug?
BTW, Comeau online and presumably Visual C++ (it was originally from
Microsoft demo code) don't complain about this code, but then, that
could just be because no diagnostic is required.
Regards,
Raoul Gough.
---
[ 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: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: Fri, 30 Aug 2002 20:17:53 CST Raw View
"Raoul Gough" <RaoulGough@yahoo.co.uk> wrote...
> "Victor Bazarov" <vAbazarov@dAnai.com> wrote in message
> news:umvf1jtickji5e@corp.supernews.com...
> > "Raoul Gough" <RaoulGough@yahoo.co.uk> wrote...
> > > "Code Beaver" <pagey@pagey.info> wrote in message
> > > news:BTh99.4642$_7.469568@twister.socal.rr.com...
> > > > struct A {
> > > > struct X { } ;
> > > > int X ;
> > > > } ;
> > > [snip]
> > >
> > > I'm confused. I recently had to look up the rules for a struct
> similar
> > > to A in the example, and eventually found 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."
> > >
> > > Wouldn't this rule make the struct definition ill-formed in the
> first
> > > place, and remove any potential for ambiguity in the template?
> >
> >
> > No. When struct X is defined, the name 'X' is not "used", but
> > "introduced" (or "defined") as a type-id. When 'X' is declared
> > on the next line, 'X' is "introduced" as an [sub-]object-id.
> > No conflict. "int X" hides "struct X" (see 3.3.7, paragraph 2).
>
> OK, I missed the distinction between "using" and "introducing". Just
> to confirm my understanding, the following would also be valid:
>
> typedef int foo;
>
> struct bar {
> foo foo; // "introduce" member foo of type ::foo
> };
>
> I ask because gcc 3.1 rejects it:
>
> $ f:/mingw/bin/g++ -c typename_reuse.cc
> typename_reuse.cc:4: declaration of `foo bar::foo'
> typename_reuse.cc:1: changes meaning of `foo' from `typedef int foo'
>
> I reported this in relation to an already opened gcc bug and was told
> that the simple code example was ill-formed.
It isn't ill-formed. They are mistaken. I think you should
always ask for a justification based on the quote from the
Standard. If they miss it, you could suggest a certain part
that you think is relevant and see how they react. Makes them
look and think. Even if you happen to make a mistake and they
prove it, the truth is the ultimate result. Of course, letting
them know how other compilers behave and involing the other
compiler developers in the discussion should also be seen as
useful, I think.
> I did some reading and
> assumed that the section I quoted was the reason for this. So it
> really is a gcc bug?
Yes, seems like it.
> BTW, Comeau online and presumably Visual C++ (it was originally from
> Microsoft demo code) don't complain about this code, but then, that
> could just be because no diagnostic is required.
If the program is ill-formed, shouldn't the diagnostic always
be required? I know, the text sometimes says, "program is ill-
formed, no diagnostic is required", but it just doesn't seem
right...
Victor
--
Please remove capital A's from my address when replying by mail
---
[ 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: "Raoul Gough" <RaoulGough@yahoo.co.uk>
Date: 31 Aug 2002 12:25:07 GMT Raw View
"Victor Bazarov" <vAbazarov@dAnai.com> wrote in message
news:umvstcq2apva12@corp.supernews.com...
> "Raoul Gough" <RaoulGough@yahoo.co.uk> wrote...
> > > > "Code Beaver" <pagey@pagey.info> wrote in message
> > > > news:BTh99.4642$_7.469568@twister.socal.rr.com...
> > > > > struct A {
> > > > > struct X { } ;
> > > > > int X ;
> > > > > } ;
[snip reference to 3.3.6/2]
> > typedef int foo;
> >
> > struct bar {
> > foo foo; // "introduce" member foo of type ::foo
> > };
> >
> > I ask because gcc 3.1 rejects it:
> >
> > $ f:/mingw/bin/g++ -c typename_reuse.cc
> > typename_reuse.cc:4: declaration of `foo bar::foo'
> > typename_reuse.cc:1: changes meaning of `foo' from `typedef int
foo'
> >
> > I reported this in relation to an already opened gcc bug and was
told
> > that the simple code example was ill-formed.
>
> It isn't ill-formed. They are mistaken. I think you should
> always ask for a justification based on the quote from the
> Standard. If they miss it, you could suggest a certain part
> that you think is relevant and see how they react. Makes them
> look and think.
Actually, I already tried all that you suggest. Still, it would be
unreasonable to blame the people who maintain gcc voluntarily.
Especially since I probably learnt more by reading up on this stuff
myself.
> Even if you happen to make a mistake and they
> prove it, the truth is the ultimate result. Of course, letting
> them know how other compilers behave and involing the other
> compiler developers in the discussion should also be seen as
> useful, I think.
>
> > I did some reading and
> > assumed that the section I quoted was the reason for this. So it
> > really is a gcc bug?
>
> Yes, seems like it.
I think I now see a fundamental different between the two examples. In
the case "foo foo", the code actually *does* use the type name foo in
the class scope. Since this then gets hidden by the member variable of
the same name, I think 3.3.6/2 really does make the code invalid. This
seems logical to me now, but yesterday I was convinced of the
opposite. Fortunately, I don't actually want to write code like that
anyway.
>
> > BTW, Comeau online and presumably Visual C++ (it was originally
from
> > Microsoft demo code) don't complain about this code, but then,
that
> > could just be because no diagnostic is required.
>
> If the program is ill-formed, shouldn't the diagnostic always
> be required? I know, the text sometimes says, "program is ill-
> formed, no diagnostic is required", but it just doesn't seem
> right...
It would certainly make it easier to see the compiler writer's opinion
on the matter :-) OTOH, I think some of the error cases are not
feasible to detect.
Regards,
Raoul Gough.
---
[ 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: rani_sharoni@hotmail.com (Rani Sharoni)
Date: 31 Aug 2002 12:25:11 GMT Raw View
Code Beaver <pagey@pagey.info> wrote in message news:<BTh99.4642$_7.469568@twister.socal.rr.com>...
> [moderator's note: Forwarded to C++ Committee. -sdc]
>
> Section 14.6[temp.res] paragraph 4 uses the following example to show that
> qualified name lookup described in Section 3.4.3[basic.lookup.qual] applies
> even in the presence of "typename":
>
> struct A {
> struct X { } ;
> int X ;
> } ;
> template<class T> void f(T t) {
> typename T::X x ; // ill-formed: finds the data member X
> // not the member type X
> }
>
Open issue #345 (Misleading comment on example in templates chapter)
already mentions this defect.
Rani
---
[ 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: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 31 Aug 2002 20:05:01 GMT Raw View
In article <umvstcq2apva12@corp.supernews.com>, Victor Bazarov
<vAbazarov@dAnai.com> writes
>If the program is ill-formed, shouldn't the diagnostic always
>be required? I know, the text sometimes says, "program is ill-
>formed, no diagnostic is required", but it just doesn't seem
>right...
That is because requiring diagnosis would sometimes result in compile
times (and link times) becoming orders of magnitude higher than they
already are. If we tried to require something like that, the requirement
would be universally honoured in the breech, and the Standard would come
into disrepute. No sane implementor is going to vote for something whose
implementation will result in an unsaleable product.
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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: Code Beaver <pagey@pagey.info>
Date: 28 Aug 2002 18:27:09 GMT Raw View
[moderator's note: Forwarded to C++ Committee. -sdc]
Section 14.6[temp.res] paragraph 4 uses the following example to show that
qualified name lookup described in Section 3.4.3[basic.lookup.qual] applies
even in the presence of "typename":
struct A {
struct X { } ;
int X ;
} ;
template<class T> void f(T t) {
typename T::X x ; // ill-formed: finds the data member X
// not the member type X
}
This example is confusing because the definition of the template function
itself is not ill formed unless it is instantiated with "A" as the template
parameter. In other words, the example should be modified to something
like:
struct A {
struct X { } ;
int X ;
} ;
struct B {
struct X { } ;
} ;
template<class T> void f(T t) {
typename T::X x ;
}
void foo() {
A a ;
B b ;
f(b) ; // OK -- finds member type B::X.
f(a) ; // ill-formed: finds the data member A::X not
// the member type A::X.
}
Thanks,
Pagey
[ 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: "Raoul Gough" <RaoulGough@yahoo.co.uk>
Date: Fri, 30 Aug 2002 13:17:38 CST Raw View
"Code Beaver" <pagey@pagey.info> wrote in message
news:BTh99.4642$_7.469568@twister.socal.rr.com...
>
> [moderator's note: Forwarded to C++ Committee. -sdc]
>
> Section 14.6[temp.res] paragraph 4 uses the following example to
show that
> qualified name lookup described in Section 3.4.3[basic.lookup.qual]
applies
> even in the presence of "typename":
>
> struct A {
> struct X { } ;
> int X ;
> } ;
> template<class T> void f(T t) {
> typename T::X x ; // ill-formed: finds the data member X
> // not the member type X
> }
[snip]
I'm confused. I recently had to look up the rules for a struct similar
to A in the example, and eventually found 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."
Wouldn't this rule make the struct definition ill-formed in the first
place, and remove any potential for ambiguity in the template?
Regards,
Raoul Gough.
---
[ 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 ]