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: unassignedclangb...@nondot.org
Reporter: billy.on...@gmail.com
CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
llvm-bugs@lists.llvm.org, richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs