[cfe-users] dynmaic_cast in uninstantiated function templates

via cfe-users cfe-users at lists.llvm.org
Thu Nov 1 05:51:20 PDT 2018

Thanks for the clarification. So a solution could be a template make_dependent

template<class X, class Y>
struct make_dependent
  typedef X type;

template<class T>
void fn(A* a, T& x)
  dynamic_cast<typename make_dependent<B*, T>::type>(a);

The standard doesn't supply any similar, does it?

Best Olaf

-----Urspr√ľngliche Nachricht-----
Von: Mat Sutcliffe [mailto:oktal3700 at gmail.com] 
Gesendet: Mittwoch, 24. Oktober 2018 18:42
An: Krzikalla, Olaf; cfe-users at lists.llvm.org
Betreff: Re: [cfe-users] dynmaic_cast in uninstantiated function templates

On Wed, 24 Oct 2018 at 02:06, Olaf wrote:
> the code below compiles on gcc and icc, but not on clang with the error:
> source_file.cpp:14:16: error: 'B' is an incomplete type
>   if (auto b = dynamic_cast<B*>(a))
> However fn is an uninstantiated function template.
> Is this a glitch in clang or is clang the only one right here?
> class B;
> template<class T>
> void fn(A* a, T& x)
> {
>   dynamic_cast<B*>(a);
> }

All three compilers are correct here, as far as the standard is
concerned. The code is ill-formed, but implementations are not
required to diagnose this kind of error. There is no type T that could
produce a well-formed instantiation of fn.

More information about the cfe-users mailing list