Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Switch to more reliable way of calling data_type initialization function
  • Loading branch information
AMDmi3 committed Jan 11, 2021
1 parent 83c804d commit bfa948a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/database/data_type.h
Expand Up @@ -52,6 +52,15 @@ template <typename T>
class data_type : public data_type_base
{
public:
data_type() {
// this check is required for class_initialized variable and,
// correspondingly, data_type::initialize_class() call not to
// be initialized away
if (!class_initialized) {
throw std::runtime_error("Never reached");
}
}

static T *get(const std::string &identifier)
{
if (identifier == "none") {
Expand Down Expand Up @@ -308,12 +317,7 @@ class data_type : public data_type_base
static inline std::map<std::string, qunique_ptr<T>> instances_by_identifier;
static inline std::map<std::string, T *> instances_by_alias;
static inline data_module_map<std::vector<sml_data>> sml_data_to_process;
#ifdef __GNUC__
//the "used" attribute is needed under GCC, or else this variable will be optimized away (even in debug builds)
static inline bool class_initialized [[gnu::used]] = data_type::initialize_class();
#else
static inline bool class_initialized = data_type::initialize_class();
#endif
};

}

0 comments on commit bfa948a

Please sign in to comment.