[cfe-dev] crash with explicit instantiation (PR24629)

don hinton via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 11 13:46:12 PST 2016


The following code will crash the clang:

  template<class T>
  struct X {
    void bar(T t) {}
    void foo(T t, int i) {}

    template<class U>
    void foo(T t, U i) {}
  };

  template class X<double>;
  template void X<double>::bar(double t);  // error, reports duplicate

  template void X<double>::foo(double t, int i); // crashes, but should
report duplicate

  template void X<double>::foo<int>(double t, int i); // crashes, but
should be okay


The error for bar() is correct, since it was already explicitly
instantiated by X, however, I believe the first, non-templatized, version
of foo() should have the same behavior, but it crashes, as does the
templatized version.

But if I just use them without explicit instantiation, they work as
expected, e.g.:

  X<double> x;
  x.bar(1.2);
  x.foo(1.2, 1);
  x.foo<int>(1.2, 1);

With the non-templatized version of foo() taking precidence.

Before I make a run at fixing this, I just wanted to make sure I was doing
the right thing.

thanks...
don
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160211/0b27ac4e/attachment.html>


More information about the cfe-dev mailing list