[llvm-bugs] [Bug 51414] New: Exporting nested classes doesn't compile and link with Clang on Windows
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Aug 9 08:01:17 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51414
Bug ID: 51414
Summary: Exporting nested classes doesn't compile and link with
Clang on Windows
Product: clang
Version: 12.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: peterghost86 at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
The following code won't compile and link using `clang-cl /std:c++17 test.cpp`.
#include <optional>
#include <vector>
#include <string>
#include <iostream>
#define EXPORT_OUTER __declspec(dllexport)
#define EXPORT_INNER __declspec(dllexport)
class EXPORT_OUTER A
{
public:
class EXPORT_INNER B
{
public:
B(
const std::optional<std::vector<std::string>> &opt =
std::nullopt)
{
}
};
};
int main()
{
auto b = A::B();
return 0;
}
Error:
test-e1dae6.obj: error LNK2019: Unresolved external symbol "public: __cdecl
std::optional<class std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std:: allocator<char> >,class std::allocator<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char>>>> >::~optional<class std:: vector<class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
>,class std::allocator<class std::basic_string<char,struct
std::char_traits<char >,class std::allocator<char>>>> >(void)"
(??1?$optional at V?$vector at V?$basic_string at DU?$char_traits at D@std@@V?$allocator
@D at 2@@std@@V?$allocator at V?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@@2@@std@@@
std@@QEAA at XZ), the symbol is referenced in the function main
test.exe: fatal error LNK1120: 1 unresolved external command
clang-cl: error: linker command failed with exit code 1120 (use -v to see
invocation)
However, the same code compiles and links if
1. using cl.exe from MSVC
2. using `#define EXPORT_INNER` instead
3. removing the default value of `opt` in the ctor of the class B and passing
in `std::nullopt` explicitly
--
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/20210809/47750c96/attachment.html>
More information about the llvm-bugs
mailing list