Skip to content

Commit 0c5242e

Browse files
committed
COMP: Fix MSVC linker errors for jsonxx Empty* globals
Replace `static const Object EmptyObject = {};` (and Array, Value variants) with `inline` accessor functions returning a local static. The `static const` form creates per-TU copies whose constructors reference symbols defined in jsonxx.cc — when the header test TU links against the shared library on Windows, MSVC cannot resolve these symbols because they lack __declspec(dllexport). The `inline` function with a local static is C++17-safe, ODR-correct, and avoids the linker dependency entirely.
1 parent f5131b0 commit 0c5242e

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

include/jsonxx.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ class Object
219219
std::string odd;
220220
};
221221

222-
static const Object EmptyObject = {};
222+
inline const Object &
223+
EmptyObject()
224+
{
225+
static const Object instance;
226+
return instance;
227+
}
223228

224229
class Array
225230
{
@@ -298,7 +303,12 @@ class Array
298303
container values_;
299304
};
300305

301-
static const Array EmptyArray = {};
306+
inline const Array &
307+
EmptyArray()
308+
{
309+
static const Array instance;
310+
return instance;
311+
}
302312

303313
// A value could be a number, an array, a string, an object, a
304314
// boolean, or null
@@ -515,7 +525,12 @@ class Value
515525
parse(std::istream & input, Value & value);
516526
};
517527

518-
static const Value EmptyValue = {};
528+
inline const Value &
529+
EmptyValue()
530+
{
531+
static const Value instance;
532+
return instance;
533+
}
519534

520535
template <typename T>
521536
bool

0 commit comments

Comments
 (0)