[C++] Unreviewed patches

Gabriel Dos Reis gdr@integrable-solutions.net
Sat Jan 10 01:35:00 GMT 2004


"Giovanni Bajo" <giovannibajo@libero.it> writes:

| Gabriel Dos Reis wrote:
| 
| >>> ------------------------------------
| >>> struct B {
| >>>   typedef int K;
| >>> };
| >>> template <class T> struct D : T {
| >>>   typedef typename D::K K2;
| >>> };
| >>> ------------------------------------
| >> I do not think this is valid. IIU 224 correctly, the
| >> nested-name-specifier (which is D) is not dependent, therefore we do
| >> the lookup and definition
| >
| > I disagree.  The 'D' in "D::K" is the injected class-name, and
| > is therefore equivalent to D<T>, and is dependent.
| 
| D<T>::K or D::K are non dependent names, because of the resolution of DR224.
| The new 14.6.2.1 introduces the term "current instantiation", which is defined
| as "the injected class name" or "name of the class template followed by the
| template argument list of the primary template (as described below) enclosed in
| <>", which in our case is exactly D and D<T>. Then, it introduces a "member of
| the current instantiation", which is (among the others) a qualified-id in which
| the nested-name-specifier refers to the current instatiation. Thus, D::K or
| D<T>::K both refer to the current instantiation. Then, the definition of "type
| dependent" does not include "members of the current instiantiation"
| specifically to rule out these cases.
| 
| >> time (looking in D and any non-dependent bases), and in this case we
| >> find nothing, so it is an error.
| >
| > No, you cannot look into D, because it is dependent.
| 
| DR224 is about changing the definition of dependent from "syntatically
| dependent" to "semantically dependent".

All those break codes for no reason and the assertion that the new
definition is "semantic"-based is also plain wrong.  I'll take this
issue to the committee, but in the meantime, please DO NOT apply any
patch to that effect because the "new" definition is unnecesarily
complicated, awful, and wrong.

    struct  A { 
       void f();
    };

    template<class T>
    struct X : T {
      void g() { X x; x.f(); }          // #1
    };


if 'X' in X<T>::g is not dependent, then then we'll be rejecting that
definition because ordinary name lookup will not find 'f'.  That
breaks  *LOTS* of code that were written against C++98 (and I think
C++03).  In particular, it breaks the idiom known as "base class
parameterized by derived classes". 

-- Gaby



More information about the Gcc-patches mailing list