Skip to content

Commit bfa948a

Browse files
committed
Switch to more reliable way of calling data_type initialization function
1 parent 83c804d commit bfa948a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/database/data_type.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ template <typename T>
5252
class data_type : public data_type_base
5353
{
5454
public:
55+
data_type() {
56+
// this check is required for class_initialized variable and,
57+
// correspondingly, data_type::initialize_class() call not to
58+
// be initialized away
59+
if (!class_initialized) {
60+
throw std::runtime_error("Never reached");
61+
}
62+
}
63+
5564
static T *get(const std::string &identifier)
5665
{
5766
if (identifier == "none") {
@@ -308,12 +317,7 @@ class data_type : public data_type_base
308317
static inline std::map<std::string, qunique_ptr<T>> instances_by_identifier;
309318
static inline std::map<std::string, T *> instances_by_alias;
310319
static inline data_module_map<std::vector<sml_data>> sml_data_to_process;
311-
#ifdef __GNUC__
312-
//the "used" attribute is needed under GCC, or else this variable will be optimized away (even in debug builds)
313-
static inline bool class_initialized [[gnu::used]] = data_type::initialize_class();
314-
#else
315320
static inline bool class_initialized = data_type::initialize_class();
316-
#endif
317321
};
318322

319323
}

0 commit comments

Comments
 (0)