Topic: Implicit class template instantiation required?


Author: Gabriel Dos Reis <gdr@cs.tamu.edu>
Date: Fri, 3 Sep 2004 17:32:15 GMT
Raw View
cludwig@cdc.informatik.tu-darmstadt.de (Christoph Ludwig) writes:

[...]

| Compiled with gcc 3.4.1, g<B>(0) returns 1 as one would expect according to
| DR#337. But g<A<int> >(0) returns 0, even though A<int> is also abstract.
|
| When discussing this issue on GCC bugzilla, Giovanni Bajo wrote
| <URL:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17232>:
|
| > The problem is that A<int> was not instantiated at the point of call. So
| > the compiler does not know yet if A<int> is an abstract type or not -- it
| > will have to instantiate that to do so. Now, I am not sure we should force
| > an instantiation just because we are trying to form an array type and we
| > need to check for abstractness, I fear this requires a clarification from
| > C++ gurus.
|
| I am certainly not an expert but I understand 14.7.1/p4 such that an
| implicit instantiation of A<int> is required - because the semantics of the
| program depend on the instantiation and the class template specialization
| takes part in overload resolution.
|
| Can someone very or correct my reading of the standard, please? Thanks.

Because the presence of the instantiation affects the semantics of the
program, there is no doubt that the implicit instantiation is required
by the very paragraph you quote.  In other words, GCC is defective.

--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: cludwig@cdc.informatik.tu-darmstadt.de (Christoph Ludwig)
Date: Tue, 31 Aug 2004 04:31:23 GMT
Raw View
Hi,

please consider the following program that tries to take advantage of the
resolution of DR#337
<URL:http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#337>:

  template<typename T>
  class A {
    virtual void f() = 0;
  };

  class B {
    virtual void f() = 0;
  };

  template<typename T>
  int g(T (*)[1]) {
    return 0;
  }

  template<typename T>
  int g(...) {
    return 1;
  }

  int main() {
    return  (g< A<int> >(0) == g< B >(0)) ;
  }

Compiled with gcc 3.4.1, g<B>(0) returns 1 as one would expect according to
DR#337. But g<A<int> >(0) returns 0, even though A<int> is also abstract.

When discussing this issue on GCC bugzilla, Giovanni Bajo wrote
<URL:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17232>:

> The problem is that A<int> was not instantiated at the point of call. So
> the compiler does not know yet if A<int> is an abstract type or not -- it
> will have to instantiate that to do so. Now, I am not sure we should force
> an instantiation just because we are trying to form an array type and we
> need to check for abstractness, I fear this requires a clarification from
> C++ gurus.

I am certainly not an expert but I understand 14.7.1/p4 such that an
implicit instantiation of A<int> is required - because the semantics of the
program depend on the instantiation and the class template specialization
takes part in overload resolution.

Can someone very or correct my reading of the standard, please? Thanks.

Christoph

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]