This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] [PR13813] Incomplete type for member variables of class templates


Hello,

This is more a RFC. Consider this testcase:
--------------------------------------------
class E;
template <int> struct Z1 { E e; };  // #1
template <int> struct Z2 { class F; F f; };  // #2
--------------------------------------------

About #1: If you read DR206, the code is ill-formed (no diagnostic required) if
E is defined later and Z2 is instantiated. EDG rejects it, MSVC71 accepts. I
think it makes a lot of sense for it to be ill-formed because E is a
non-dependent name, so delaying the semantic constraint check till
instantiation point is weird. For instance, think of "sizeof(e)": should it be
rejected or considered value-dependent (as MSVC71 appears to do)? Currently we
emit a mysterious "invalid use of non-static data member" for the sizeof
expression. I find the DR resolution rather surprising and... incomplete (sorry
for the pun), and I propose to have the code rejected. The trivial patch
attacched to this mail makes it so.

About #2: nested classes are always dependent types (see DR108, later re-worded
by DR224), in fact they can be specialized. So it makes sense to wait until
instantiation time to check for completeness. And that's what we do already.
EDG refuses it, but I think it's wrong here. In this case, sizeof(f) is
value-dependent because f is type-dependent.

The patch has been tested on i686-pc-linux-gnu with no new regressions. OK for
mainline?

Giovanni Bajo


2004-01-23  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        DR206
        PR c++/13813
        * decl.c (grokdeclarator): Check immediatly type completeness for
        non-dependent types.


2004-01-23  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        DR206
        PR c++/13813
        * g++.dg/template/member4.C: New test.


Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1175
diff -c -3 -p -r1.1175 decl.c
*** decl.c 17 Jan 2004 18:59:44 -0000 1.1175
--- decl.c 23 Jan 2004 13:06:45 -0000
*************** grokdeclarator (tree declarator,
*** 8177,8183 ****
       if (decl == NULL_TREE)
         return NULL_TREE;
     }
!  else if (!staticp && ! processing_template_decl
     && !COMPLETE_TYPE_P (complete_type (type))
     && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
     {
--- 8177,8183 ----
       if (decl == NULL_TREE)
         return NULL_TREE;
     }
!  else if (!staticp && !dependent_type_p (type)
     && !COMPLETE_TYPE_P (complete_type (type))
     && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
     {



// { dg-do compile }
// Contributed by Matty T. <mattyt-bugzilla at tpg dot com dot au>
// PR c++/13813 [DR206]: Check semantic constraints of members of
//   non-dependent type at instantiation time.


// DR206 explains that this is ill-formed, no diagnostic required. We emit
//  a diagnostic instead.
class E;
template < class A > class Z {
  A a;
  E e;   // { dg-error "incomplete type" }
};


// Nested classes are always dependent names.
template < class A > class Y {
  class F;
  F e;   // { dg-bogus "" "nested classes are always dependent, see DR108 and
DR224" }
};



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]