Closed
Description
Repros with Clang 17.0.3 and VS 2022 17.11 Preview 1. MSVC accepts, but Clang rejects.
C:\Temp>"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvarsall.bat" x64
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.11.0-pre.1.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\Temp>clang-cl -v
clang version 17.0.3
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\Llvm\x64\bin
C:\Temp>type meow.cpp
#include <variant>
using namespace std;
struct UDT {
UDT() {}
~UDT() {}
};
int main() {
using V = variant<int, double, UDT>;
[[maybe_unused]] V a{1729};
[[maybe_unused]] V b{3.14};
[[maybe_unused]] V c{UDT{}};
}
C:\Temp>cl /EHsc /nologo /W4 /std:c++17 /MTd /Od meow.cpp
meow.cpp
C:\Temp>cl /EHa /nologo /W4 /std:c++17 /MTd /Od meow.cpp
meow.cpp
C:\Temp>clang-cl /EHsc /nologo /W4 /std:c++17 /MTd /Od meow.cpp
C:\Temp>clang-cl /EHa /nologo /W4 /std:c++17 /MTd /Od meow.cpp
meow-aeb2d1.obj : error LNK2019: unresolved external symbol "public: __cdecl std::_Variant_storage_<0,double,struct UDT>::~_Variant_storage_<0,double,struct UDT>(void)" (??1?$_Variant_storage_@$0A@NUUDT@@@std@@QEAA@XZ) referenced in function "int `public: __cdecl std::_Variant_storage_<0,int,double,struct UDT>::_Variant_storage_<0,int,double,struct UDT><1,double,0>(struct _Variant_storage_<0,int,double,struct UDT>::integral_constant<unsigned __int64,1>,double &&)'::`1'::dtor$3" (?dtor$3@?0???$?0$00N$0A@@?$_Variant_storage_@$0A@HNUUDT@@@std@@QEAA@U?$integral_constant@_K$00@1@$$QEAN@Z@4HA)
meow-aeb2d1.obj : error LNK2019: unresolved external symbol "public: __cdecl std::_Variant_storage_<0,struct UDT>::~_Variant_storage_<0,struct UDT>(void)" (??1?$_Variant_storage_@$0A@UUDT@@@std@@QEAA@XZ) referenced in function "int `public: __cdecl std::_Variant_storage_<0,double,struct UDT>::_Variant_storage_<0,double,struct UDT><1,struct UDT,0>(struct _Variant_storage_<0,double,struct UDT>::integral_constant<unsigned __int64,1>,struct UDT &&)'::`1'::dtor$3" (?dtor$3@?0???$?0$00UUDT@@$0A@@?$_Variant_storage_@$0A@NUUDT@@@std@@QEAA@U?$integral_constant@_K$00@1@$$QEAUUDT@@@Z@4HA)
meow.exe : fatal error LNK1120: 2 unresolved externals
clang-cl: error: linker command failed with exit code 1120 (use -v to see invocation)
Reduced from the original user report DevCom-10647850 "Linking bug of std::unordered_map
with std::variant
Value Type with latest MS Visual Studio Community 2022".