Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Explicit function template instantiation leads to linker error (Regression) #62134

Open
craffael opened this issue Apr 14, 2023 · 2 comments

Comments

@craffael
Copy link

craffael commented Apr 14, 2023

Compiler Information

$ clang++-16 --version
Ubuntu clang version 16.0.1 (++20230328073357+42d1b276f779-1~exp1~20230328073502.65)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Steps to reproduce

  1. You need to create three files:

main.h

template <typename _Scalar>
struct Matrix {
  enum { IsVectorAtCompileTime = true };
};


template <typename Type>
using Vector = Matrix<Type>;

template <
    typename PlainObjectType,
    int StrideType = PlainObjectType::IsVectorAtCompileTime ? 0 : 1>
class Ref {};

template <class T>
class EigenSparseLU {
 public:
  template <class SCALAR_RHS>
  auto Apply(const Ref<Vector<SCALAR_RHS>>& rhs) const noexcept -> void;
};

main.cc

#include "main.h"

int main() {

  auto sparseLu = EigenSparseLU<double>();

  Matrix<double> q;
  sparseLu.Apply<double>({});

}

main2.cc

#include "main.h"

template <typename Scalar>
struct SparseLUImpl {
  typedef Ref<Matrix<Scalar>> BlockScalarVector;
};

template<class T>
template <class SCALAR_RHS>
auto EigenSparseLU<T>::Apply(
    const Ref<Vector<SCALAR_RHS>>& rhs) const noexcept
    -> void {
}

template auto EigenSparseLU<double>::Apply<double>(
    const Ref<Vector<double>>&) const noexcept -> void;
  1. Compile and link the three files with clang++-16 main.cc main2.cc
  2. Observe the error message:
/usr/bin/ld: /tmp/main-3e89ac.o: in function `main':
main.cc:(.text+0x1a): undefined reference to `void EigenSparseLU<double>::Apply<double>(Ref<Matrix<double>, Vector<double>::IsVectorAtCompileTime?(0) : (1)> const&) const'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Note that this only fails with Clang 16 (I don't know about trunk). It works with Clang 14 and Clang 15. Also GCC compiles it fine.

@llvmbot
Copy link
Member

llvmbot commented Apr 14, 2023

@llvm/issue-subscribers-clang-codegen

@3y3p4tch
Copy link

The issue is still present in trunk - https://clang.godbolt.org/z/M1dsWrceY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants