diff --git a/InsightsHelpers.cpp b/InsightsHelpers.cpp index 44beb098..a8896a2e 100644 --- a/InsightsHelpers.cpp +++ b/InsightsHelpers.cpp @@ -1389,7 +1389,7 @@ bool IsTrivialStaticClassVarDecl(const VarDecl& varDecl) // Should the VarDecl be evaluatable at compile-time, there is no additional guard added by the compiler. if(varDecl.isStaticLocal() and not IsEvaluatable(varDecl)) { if(const auto* cxxRecordDecl = varDecl.getType()->getAsCXXRecordDecl()) { - if(cxxRecordDecl->hasNonTrivialDestructor() or cxxRecordDecl->hasNonTrivialDefaultConstructor()) { + if(cxxRecordDecl->hasNonTrivialDestructor() or not cxxRecordDecl->hasTrivialDefaultConstructor()) { return true; } } diff --git a/tests/StaticHandler7Test.cpp b/tests/StaticHandler7Test.cpp new file mode 100644 index 00000000..a6cbeb3c --- /dev/null +++ b/tests/StaticHandler7Test.cpp @@ -0,0 +1,16 @@ +struct Data +{ + int i; + + Data(int x) + : i{x} + { + } +}; + +Data& Fun(int x) +{ + static Data mData{x}; + + return mData; +} diff --git a/tests/StaticHandler7Test.expect b/tests/StaticHandler7Test.expect new file mode 100644 index 00000000..83618a99 --- /dev/null +++ b/tests/StaticHandler7Test.expect @@ -0,0 +1,37 @@ +#include // for thread-safe static's placement new +#include // for uint64_t under Linux/GCC + +struct Data +{ + int i; + inline Data(int x) + : i{x} + { + } + +}; + + +Data & Fun(int x) +{ + static uint64_t __mDataGuard; + alignas(Data) static char __mData[sizeof(Data)]; + + if((__mDataGuard & 255) == 0) { + if(__cxa_guard_acquire(&__mDataGuard)) { + try + { + new (&__mData)Data{x}; + __mDataGuard = true; + } catch(...) { + __cxa_guard_abort(&__mDataGuard); + throw ; + } + __cxa_guard_release(&__mDataGuard); + /* __cxa_atexit(Data::~Data, &__mData, &__dso_handle); */ + } + + } + + return *reinterpret_cast(__mData); +}