Skip to content

Commit 387a38d

Browse files
committed
Fixed static visualization for types with a trivial constructor.
1 parent c91665f commit 387a38d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

InsightsHelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ bool IsTrivialStaticClassVarDecl(const VarDecl& varDecl)
13891389
// Should the VarDecl be evaluatable at compile-time, there is no additional guard added by the compiler.
13901390
if(varDecl.isStaticLocal() and not IsEvaluatable(varDecl)) {
13911391
if(const auto* cxxRecordDecl = varDecl.getType()->getAsCXXRecordDecl()) {
1392-
if(cxxRecordDecl->hasNonTrivialDestructor() or cxxRecordDecl->hasNonTrivialDefaultConstructor()) {
1392+
if(cxxRecordDecl->hasNonTrivialDestructor() or not cxxRecordDecl->hasTrivialDefaultConstructor()) {
13931393
return true;
13941394
}
13951395
}

tests/StaticHandler7Test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct Data
2+
{
3+
int i;
4+
5+
Data(int x)
6+
: i{x}
7+
{
8+
}
9+
};
10+
11+
Data& Fun(int x)
12+
{
13+
static Data mData{x};
14+
15+
return mData;
16+
}

tests/StaticHandler7Test.expect

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <new> // for thread-safe static's placement new
2+
#include <stdint.h> // for uint64_t under Linux/GCC
3+
4+
struct Data
5+
{
6+
int i;
7+
inline Data(int x)
8+
: i{x}
9+
{
10+
}
11+
12+
};
13+
14+
15+
Data & Fun(int x)
16+
{
17+
static uint64_t __mDataGuard;
18+
alignas(Data) static char __mData[sizeof(Data)];
19+
20+
if((__mDataGuard & 255) == 0) {
21+
if(__cxa_guard_acquire(&__mDataGuard)) {
22+
try
23+
{
24+
new (&__mData)Data{x};
25+
__mDataGuard = true;
26+
} catch(...) {
27+
__cxa_guard_abort(&__mDataGuard);
28+
throw ;
29+
}
30+
__cxa_guard_release(&__mDataGuard);
31+
/* __cxa_atexit(Data::~Data, &__mData, &__dso_handle); */
32+
}
33+
34+
}
35+
36+
return *reinterpret_cast<Data*>(__mData);
37+
}

0 commit comments

Comments
 (0)