[llvm-bugs] [Bug 45367] New: Aggregates containing elements with constexpr constructors are not statically initalized
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Mar 31 00:36:21 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45367
Bug ID: 45367
Summary: Aggregates containing elements with constexpr
constructors are not statically initalized
Product: clang
Version: 10.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++2a
Assignee: unassignedclangbugs at nondot.org
Reporter: billy.oneal at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
Created attachment 23295
--> https://bugs.llvm.org/attachment.cgi?id=23295&action=edit
repro.cpp
Previously reported as https://github.com/microsoft/STL/issues/661
In the following example, should_be_statically_initalized should be eligible
for static initialization, then the dynamic initializer for foo that calls
bar() should run, resulting in the asserts in main(). However, clang only seems
to give these static initializers if the varaible is {}'d.
C:\Users\billy\Desktop>type repro.cpp
#include <assert.h>
struct FakeAtomic {
int example;
constexpr FakeAtomic() noexcept : example{} {}
int operator++() { return ++example; }
int operator++(int) { return example++; }
int load() const { return example; }
};
struct Meow {
FakeAtomic data[2];
char padding[64];
};
int bar();
int foo = bar();
#ifdef WORKAROUND
Meow should_be_statically_initalized[256]{};
#else
Meow should_be_statically_initalized[256];
#endif
int bar() { return should_be_statically_initalized[0].data[0]++; }
int main() {
assert(foo == 0);
assert(should_be_statically_initalized[0].data[0].load() == 1);
}
C:\Users\billy\Desktop>clang-cl /EHsc /W4 /WX .\repro.cpp
C:\Users\billy\Desktop>.\repro.exe
Assertion failed: should_be_statically_initalized[0].data[0].load() == 1, file
.\repro.cpp, line 30
C:\Users\billy\Desktop>clang-cl /DWORKAROUND /EHsc /W4 /WX .\repro.cpp
C:\Users\billy\Desktop>.\repro.exe
C:\Users\billy\Desktop>
--
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/20200331/34baff67/attachment-0001.html>
More information about the llvm-bugs
mailing list