This is the mail archive of the gcc@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]

Templates with incomplete types


Consider the following test case:
struct abc;

template <typename T>
void foo(T, abc* p)
{
  p->do_it();
}

struct abc { void do_it(); };

void invoker()
{
  abc tmp;
  foo(17, &tmp);
}

You will notice that struct abc is incomplete at the point of template definition but complete at the point of instantiation. The C++ standard (14.6/7) says: "If a type used in a non-dependent name is incomplete at the point at which a template is defined but is complete at the point at which an instantiation is done, and if the completeness of that type affects whether or not the program is well-formed or affects the semantics of the program, the program is ill-formed; no diagnostic is required."

So we are within our rights either to accept this code or to reject it. Arguably the latter is the better choice, since diagnosing ill-formed code is a Good Thing.

On the other hand, in 3.3 we used to accept this code, and I suspect a number of other compilers did too. (That's what'll happen if you do all name lookup at the point of instantiation.) I suspect there's still code out there that relies on the old behavior. Should we provide a switch that'll get the old behavior back?

--Matt


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