[llvm-bugs] [Bug 37998] New: Clang-cl link error exported class with template as base

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jun 30 04:21:52 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37998

            Bug ID: 37998
           Summary: Clang-cl link error exported class with template as
                    base
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jvapen at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20495
  --> https://bugs.llvm.org/attachment.cgi?id=20495&action=edit
Reproduction

Using MSVC 2017 and Clang-cl 6.0.0
Given link error:

u.clang.obj : error LNK2019: unresolved external symbol "private: int * __cdecl
NS::A<struct N::S>::get<int>(void)" (??$get at H@?$A at US@N@@@NS@@AEAAPEAHXZ)
referenced in function "int __cdecl func(int,char * *)" (?func@@YAHHPEAPEAD at Z)

In attachment, you can find the same files as below.

run.cmd
-------
cl.exe /nologo /c /GR /EHsc /fp:precise /FS /std:c++17 /diagnostics:caret /O2
/I. /MDd /Zc:forScope /bigobj /Zc:wchar_t t.cpp
cl.exe /nologo /c /GR /EHsc /fp:precise /FS /std:c++17 /diagnostics:caret /O2
/I. /MDd /Zc:forScope /bigobj /Zc:wchar_t u.cpp
cl.exe /nologo /c /GR /EHsc /fp:precise /FS /std:c++17 /diagnostics:caret /O2
/I. /MDd /Zc:forScope /bigobj /Zc:wchar_t m.cpp
move t.obj t.msvc.obj
move u.obj u.msvc.obj
move m.obj m.msvc.obj
link m.msvc.obj t.msvc.obj u.msvc.obj

clang-cl.exe -fms-compatibility-version=19.11 /DBOOST_USE_WINDOWS_H -w
-Wno-unused-command-line-argument  /nologo /c /GR /EHsc /fp:precise /FS
/std:c++17 /diagnostics:caret /O2 /I. /MDd /Zc:forScope /bigobj /Zc:wchar_t
t.cpp
clang-cl.exe -fms-compatibility-version=19.11 /DBOOST_USE_WINDOWS_H -w
-Wno-unused-command-line-argument  /nologo /c /GR /EHsc /fp:precise /FS
/std:c++17 /diagnostics:caret /O2 /I. /MDd /Zc:forScope /bigobj /Zc:wchar_t
u.cpp
clang-cl.exe -fms-compatibility-version=19.11 /DBOOST_USE_WINDOWS_H -w
-Wno-unused-command-line-argument  /nologo /c /GR /EHsc /fp:precise /FS
/std:c++17 /diagnostics:caret /O2 /I. /MDd /Zc:forScope /bigobj /Zc:wchar_t
m.cpp
move t.obj t.clang.obj
move u.obj u.clang.obj
move m.obj m.clang.obj
link m.clang.obj t.clang.obj u.clang.obj


t.h
---
#include <type_traits>
#ifdef EXPORT_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif

namespace N {
struct S {};
} // namespace N

namespace NS {

struct I {
  virtual ~I() = default;
  virtual int *f() = 0;
};

template <typename T> class A : public I {
public:
  explicit A() = default;
  virtual ~A() = default;

  A(const A &) = default;
  A(A &&) = default;

  A &operator=(const A &) = default;
  A &operator=(A &&) = default;

  virtual int *f() override { return get<int>(); }

private:
  template <typename Q, bool selection = std::is_base_of<Q, T>::value>
  struct Impl {
    Q *get();
  };

  template <typename Q> struct Impl<Q, false> {
    Q *get() { return nullptr; }
  };

  //! Wrapper method
  template <typename Q> Q *get();
};
} // namespace NS
namespace N {
class EXPORT B : public NS::A<S> {
public:
  explicit B();
  virtual ~B();

  B(const B &) = default;
  B(B &&) = default;

  B &operator=(const B &) = default;
  B &operator=(B &&) = default;
};
} // namespace N

t.cpp
-----
#define EXPORT_DLL
#include "t.h"

namespace NS {

template <typename T>
template <typename Q, bool selection>
Q *A<T>::Impl<Q, selection>::get() {
  static int i = 42;
  return &i;
}

template <typename T> template <typename Q> Q *A<T>::get() {
  return Impl<Q>().get();
}

} // namespace NS

using namespace N;
using namespace NS;

B::B() = default;
B::~B() = default;

template class EXPORT NS::A<S>;

u.cpp
-----
#define EXPORT_DLL
#include "t.h"

using namespace N;

int func(int, char **) {
  auto b = B{};

  return *b.f();
}

m.cpp
-----
#include "t.h"

using namespace N;

int main(int, char **) {
  auto b = B{};

  return *b.f();
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180630/11aa1eb0/attachment.html>


More information about the llvm-bugs mailing list