Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion InsightsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/StaticHandler7Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct Data
{
int i;

Data(int x)
: i{x}
{
}
};

Data& Fun(int x)
{
static Data mData{x};

return mData;
}
37 changes: 37 additions & 0 deletions tests/StaticHandler7Test.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <new> // for thread-safe static's placement new
#include <stdint.h> // 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<Data*>(__mData);
}