<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - possible silent bad code generation with inline static data member in clang-cl"
href="https://bugs.llvm.org/show_bug.cgi?id=41409">41409</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>possible silent bad code generation with inline static data member in clang-cl
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>other
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++'17
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>powerchord@web.de
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>// header.h
#include <iostream>
struct A
{
A() { std::cout << "ctor " << this << std::endl; }
~A() { std::cout << "dtor " << this << std::endl; }
void f() { std::cout << "f " << this << std::endl; }
};
struct S
{
inline static A a; // C++17 inline variable, thus also a definition
};
-----------------------------------------
// TU1.cpp
#include "header.h"
int main()
{
S::a.f();
}
-----------------------------------------
// TU2.cpp
#include "header.h"
-----------------------------------------
// TU3.cpp
#include "header.h"
-----------------------------------------
// TU4.cpp
#include "header.h"
-----------------------------------------
This program prints (with some random address):
ctor 010D4020
ctor 010D4020
ctor 010D4020
ctor 010D4020
f 010D4020
dtor 010D4020
dtor 010D4020
dtor 010D4020
dtor 010D4020
These are four initializations for the one and only object of A (in fact one
per TU) instead of exactly one (as C++17 demands).
The program should print:
ctor 010D4020
f 010D4020
dtor 010D4020
I first reported this bug for clang-cl 6 (<a class="bz_bug_link
bz_status_NEW "
title="NEW - Clang/LLVM 7.0.1 on Windows initializes inline static data member multiple times"
href="show_bug.cgi?id=37903">bug 37903</a> and <a class="bz_bug_link
bz_status_NEW "
title="NEW - Clang/LLVM 7.0.1 lld-link.exe initializes inline static data member multiple times"
href="show_bug.cgi?id=38171">bug 38171</a>).
MSVC had the same bug, but Microsoft has fixed it (at least in VS2019):
<a href="https://developercommunity.visualstudio.com/content/problem/261624/multiple-initializations-of-inline-static-data-mem.html">https://developercommunity.visualstudio.com/content/problem/261624/multiple-initializations-of-inline-static-data-mem.html</a>
See also <a href="https://stackoverflow.com/q/50982390/8731417">https://stackoverflow.com/q/50982390/8731417</a>.
I wonder why this bug has not been fixed yet because to me it seems pretty
serious. Do I rate that wrong?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>