[cfe-dev] Name lookup of class member vs template parameter

Richard Smith richard at metafoo.co.uk
Tue Nov 26 13:18:08 PST 2013


On Tue, Nov 26, 2013 at 10:26 AM, Rahul Jain <1989.rahuljain at gmail.com>wrote:

>
> Hi all,
>
> This is with respect to the following test case:
>
> struct A {
>     struct B { typedef int X; };
> };
>
> template<class B> struct C : A {
>     B::X q; // Ok: A::B.
>     struct U { typedef int X; };
>     template<class U>
>         struct D;
> };
>
> template<class B>
> template<class U>
> struct C<B>::D {
>     typename U::X r; // { dg-error "" }
> };
>
> C<int>::D<double> y;
>
> As far as I am able to make out, this code compiles fine with Clang,
> because the statement   typename U::X r; resolves for U by looking up the
> class members first and than the template parameter list.
>
> But isnt it supposed to throw an error based on the following wordings
> from the standard (The wordings in the bracket are of interest to us):
>
> In the definition of a member of a class template that appears outside of
> the class template definition, the name of a member of the class template
> hides the name of a template-parameter of any enclosing class templates
> (but not a template-parameter of the member if the member is a class or
> function template).
>
>
> Note: The below mentioned example is from the standards.
>
> Example:
>
> template<class T> struct A {
> struct B { /* ... */ };
> typedef void C;
> void f();
> template<class U> void g(U);
> };
>
> template<class B> void A<B>::f() {
> B b;   // A’s B, not the template parameter
> }
>
> template<class B> template<class C> void A<B>::g(C) {
> B b; // A’s B, not the template parameter
> C c; // the template parameter C, not A’s C , this is the case I suppose
> we           are not handling
> }
>
>
> Am I missing something in my analysis or is this a potential bug??
>

Yes, this is a bug.


> Inputs on this would be really helpful.
>
> Thanks,
> Rahul
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131126/d4518c99/attachment.html>


More information about the cfe-dev mailing list