Topic: Defect Report: Member access lookup - ill-formed scenarios?
Author: wmm@fastdial.net
Date: 1999/08/02 Raw View
In article <7mlthm$vrn$1@nnrp1.deja.com>,
fvali@biotrack.com wrote:
> In section 3.4.5 paragraph 1 of the C++ standard -
> There is the statement regarding the identifier immediately following
> the member access operators (., ->):
> "...If the identifier is not found, it is then looked up in the
context
> of the entire postfix-expression and shall name a class or function
> template."
>
> My question is why does the standard allow the name to resolve into a
> function template?
>
> for instance:
> struct A
> { };
> template <typename TY_>
> void tmp() { }
>
> int main()
> {
> A a;
> a.tmp<int>();
> }
> If tmp resolves into a function template that could not be found in
the
> scope of the class of the object expression, how can it ever be
> well-formed.
>
> For that matter I'm not even sure how a template-id that couldn't be
> found in the class-scope of the object expression could ever legally
> resolve to a template id in the context of the expression.
>
> For instance consider:
> template<class TY_> struct A { int i; };
> struct B : A<int> { };
>
> int main()
> {
> B b;
> b.A<int>::i = 0;
> }
>
> 'A' must always be found in B, since we can;t do something like this:
>
> typedef A C;
> b.C<int>::i = 0;
>
> Why does the standard allow name lookup to find these names?
> This seems like a defect, unless I;m missing something subtle, which
> could use further clarification in the standard.
Allowing class template names that are not found in the class of
the object-expression is for cases like the following:
template <class T> struct A {
struct B { int i; };
};
void f() {
A<int>::B ab;
ab.A<int>::B::i = 2;
}
However, I think your point with respect to template function
names is well-taken, and I'll add this to the issues list.
--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: fvali@biotrack.com
Date: 1999/07/31 Raw View
In section 3.4.5 paragraph 1 of the C++ standard -
There is the statement regarding the identifier immediately following
the member access operators (., ->):
"...If the identifier is not found, it is then looked up in the context
of the entire postfix-expression and shall name a class or function
template."
My question is why does the standard allow the name to resolve into a
function template?
for instance:
struct A
{ };
template <typename TY_>
void tmp() { }
int main()
{
A a;
a.tmp<int>();
}
If tmp resolves into a function template that could not be found in the
scope of the class of the object expression, how can it ever be
well-formed.
For that matter I'm not even sure how a template-id that couldn't be
found in the class-scope of the object expression could ever legally
resolve to a template id in the context of the expression.
For instance consider:
template<class TY_> struct A { int i; };
struct B : A<int> { };
int main()
{
B b;
b.A<int>::i = 0;
}
'A' must always be found in B, since we can;t do something like this:
typedef A C;
b.C<int>::i = 0;
Why does the standard allow name lookup to find these names?
This seems like a defect, unless I;m missing something subtle, which
could use further clarification in the standard.
-thanks
-fais
I included all of 3.4.5 paragraph 1 for general reference at the bottom
of this post.
3.4.5 Class member access
1 In a class member access expression (5.2.5), if the . or -> token is
immediately followed by an identifier followed by a <, the identifier
must be looked up to determine whether the < is the beginning of a
template argument list (14.2) or a less-than operator. The identifier is
first looked up in the class of the object expression. If the identifier
is not found, it is then looked up in the context of the entire
postfix-expression and shall name a class or function template. If the
lookup in the class of the object expression finds a template, the name
is also looked up in the context of the entire postfix-expression and
--- if the name is not found, the name found in the class of the object
expression is used, otherwise
--- if the name is found in the context of the entire postfix-expression
and does not name a class template,
the name found in the class of the object expression is used, otherwise
--- if the name found is a class template, it must refer to the same
entity as the one found in the class of the object expression, otherwise
the program is ill-formed.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]