<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63618>63618</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Undefined reference to global variable defined in the same file (in MSVC mode)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
adalisk-emikhaylov
</td>
</tr>
</table>
<pre>
```cpp
struct A
{
~A() {}
};
struct B
{
int b = 0;
B(A) {}
};
struct C : public B
{
using B::B;
};
C var = A{};
int main()
{
return var.b;
}
```
Building this on Windows produces following error:
```none
lld-link: error: undefined symbol: struct C var
>>> referenced by C:\msys2\tmp\1-93d998.o:(main)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
The compiler invocation is `clang++ 1.cpp -fuse-ld=lld` (similar error without LLD, using it to show a non-localized message).
Clang version is:
```none
$ clang++ --version
clang version 16.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
```
This doesn't happen on Linux or in MinGW-compatibility mode.
Making the variable `static` doesn't change the result. Making it `inline` ICEs the compiler:
```none
fatal error: error in backend: Associative COMDAT symbol '?var@@3UC@@A' is not a key for its COMDAT.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: D:\\Tools\\LLVM_16\\bin\\clang++.exe -cc1 -triple x86_64-pc-windows-msvc19.29.30136 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name 1.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -fcoverage-compilation-dir=D:\\Repos\\sandbox -resource-dir D:\\Tools\\LLVM_16\\lib\\clang\\16 -internal-isystem D:\\Tools\\LLVM_16\\lib\\clang\\16\\include -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" -fdeprecated-macro -fdebug-compilation-dir=D:\\Repos\\sandbox -ferror-limit 19 -fmessage-length=251 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.29.30136 -std=c++14 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o C:\\msys2\\tmp\\1-cc1f29.o -x c++ 1.cpp
1. <eof> parser at end of file
2. Code generation
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
```
```none
# Crash reproducer for clang version 16.0.0
# Driver args: "--driver-mode=g++" "1.cpp" "-fuse-ld=lld"
# Original command: "D:\\Tools\\LLVM_16\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30136" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "1.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-fcoverage-compilation-dir=D:\\Repos\\sandbox" "-resource-dir" "D:\\Tools\\LLVM_16\\lib\\clang\\16" "-internal-isystem" "D:\\Tools\\LLVM_16\\lib\\clang\\16\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" "-fdeprecated-macro" "-fdebug-compilation-dir=D:\\Repos\\sandbox" "-ferror-limit" "19" "-fmessage-length=251" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30136" "-std=c++14" "-fdelayed-template-parsing" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-o" "C:\\msys2\\tmp\\1-cc1f29.o" "-x" "c++" "1.cpp"
"D:\\Tools\\LLVM_16\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30136" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "1.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-fcoverage-compilation-dir=D:\\Repos\\sandbox" "-fdeprecated-macro" "-fdebug-compilation-dir=D:\\Repos\\sandbox" "-ferror-limit" "19" "-fmessage-length=251" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30136" "-std=c++14" "-fdelayed-template-parsing" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-x" "c++" "1-df2247.cpp"
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsmV9v47gRwD-N8jKgIVH---AHx94Uhya4Q_du7_FAkSObF4oUSMpx-tDPXlCU5D9x0r1sgWzRXQSwNCRnhsPh8McVc05uNeIymdwmk80Na_zO2CUTTEn3SLCSjzv2rMz-pjDieZlM0_jH6zpJN0m6ct423MMqviWz2_gAAPCvVULnCV1AkM42fY9NknedzjTcXtEgtYcCknwD6TAoyG8TOl99teY1JPkK6qZQkl810zipt3Cb5KskX90elbxQuIY9s60_q87yeXvwt2JSx3lfsWTRN1YHLaPizE586KMbX28bqUTwzO-kA6Phd6mFeXJQWyMajg5Ko5R5Cl3QWmPDBM4VaaMxipQSREn9GELRd4ZGCyylRgHuuSqMCrIhaHtmO235p_gHFku0qDkKKJ5hHexN1pV7djSZrH1VJ5N1Rha5WCzmIxNa6TyGo4sFV0xvE3ob_k79CI6hBW6qimkBJZMKBTxJvwM8SA_cCIQMEjpvHALZgzfgEEHqveHMS3M0cRHDX3cY1NZSoT3pDtJByOKjP5CNeF0DKRuHRIkk3yglkmkajDpZScVs9Ld1yzQe7u83CV13ySN969POPAEDbTRRhjMl_4kCKnSObTGhi9FZLgXbsEfroj9vLV5Cx3DqKyHduJOwDqqy6Sgd9dNndos-hPgwn_4xHZOak6eYRaRye94HySITUBmBbQrUxsnDK-GUDoRBpxM687BjdY06pOa91M0BTIgxPEj9t99JiDrzspBK-udW99n0H9hjTG0MiSZZoTCsiPPMSx7ifrTCd0xvse1q0TXKj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