Topic: dynamic_cast depends on template instantiation?!


Author: David Vandevoorde <daveed@vandevoorde.com>
Date: 1997/09/05
Raw View

Stephen Friedrich wrote:
>
> My question boils down to something like this:
>
> Consider this:
> dynamic_cast< sub<int>* > (Base)
> and Base is really of derived type sub<int>*
>
> Is this guaranteed to work even when Base points to a
> __different template instantiation__ than used in the current
> translation unit?

There is (at least conceptually) only one instantiation
per program. I don't see why this shouldn't work.

> This is very hard to achieve from a compiler writers point of view.

Well, template instantiation is generally hard, but
I don't think this is much harder than the rest.

> OTOH if this isn't guaranteed we end up having source code that
> behaves differently if compiled with different template instantiation
> schemes.

Indeed. There can be multiple points of instantiations in
a program, and all must be ``equivalent'' (in ODR terms).
An implementation can then select any of these, or indeed
any other equivalent context, to perform an instantiation.

 Daveed
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Michael Ball <michael.ball@eng.sun.com>
Date: 1997/09/09
Raw View
Stephen Friedrich wrote:
> For example Sun's CC (4.2) gives different results when compiling with
> a single template repository and when instantiating all templates in
> the current translation unit.

This is a known bug in that compiler.  dynamic cast does not
work reliably except when using the template repository.
It's nothing basic, just a bug.

-Mike Ball-
SunMicrosystems Inc.
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]