aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-06-28 17:14:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-06-28 17:14:21 +0200
commit86db4fb7388285adc24e3aa6eb3f7ec68efd15f4 (patch)
tree115295a42619abdf8c7fde800f87cd671bed7e1e
parent41cad5bba8a718a0403c0578660c60e81c9f46e4 (diff)
Work around static initialization order issue
value_traits<T>::value_type initialization is not constexpr in VC because of pointers to function template instantiations (which apparently are not constexpr).
-rw-r--r--build2/variable14
-rw-r--r--build2/variable.cxx29
-rw-r--r--build2/variable.txx6
3 files changed, 39 insertions, 10 deletions
diff --git a/build2/variable b/build2/variable
index adc11fa..a63b5b4 100644
--- a/build2/variable
+++ b/build2/variable
@@ -372,6 +372,13 @@ namespace build2
// //
// static int compare (const T&, const T&);
//
+ // // For simple types (those that can be used as elements of containers),
+ // // type_name must be constexpr in order to sidestep the static init
+ // // order issue (in fact, that's the only reason we have it both here
+ // // and in value_type.name -- value_type cannot be constexpr because
+ // // of pointers to function template instantiations).
+ // //
+ // static const char* const type_name;
// static const build2::value_type value_type;
// };
@@ -446,6 +453,7 @@ namespace build2
static name reverse (bool x) {return name (x ? "true" : "false");}
static int compare (bool, bool);
+ static const char* const type_name;
static const build2::value_type value_type;
};
@@ -460,6 +468,7 @@ namespace build2
static name reverse (uint64_t x) {return name (to_string (x));}
static int compare (uint64_t, uint64_t);
+ static const char* const type_name;
static const build2::value_type value_type;
};
@@ -477,6 +486,7 @@ namespace build2
static name reverse (const string& x) {return name (x);}
static int compare (const string&, const string&);
+ static const char* const type_name;
static const build2::value_type value_type;
};
@@ -494,6 +504,7 @@ namespace build2
static name reverse (const path& x) {return name (x.string ());}
static int compare (const path&, const path&);
+ static const char* const type_name;
static const build2::value_type value_type;
};
@@ -511,6 +522,7 @@ namespace build2
static name reverse (const dir_path& x) {return name (x);}
static int compare (const dir_path&, const dir_path&);
+ static const char* const type_name;
static const build2::value_type value_type;
};
@@ -528,6 +540,7 @@ namespace build2
static name reverse (const abs_dir_path& x) {return name (x);}
static int compare (const abs_dir_path&, const abs_dir_path&);
+ static const char* const type_name;
static const build2::value_type value_type;
};
@@ -545,6 +558,7 @@ namespace build2
static name reverse (const name& x) {return x;}
static int compare (const name&, const name&);
+ static const char* const type_name;
static const build2::value_type value_type;
};
diff --git a/build2/variable.cxx b/build2/variable.cxx
index 17a9d52..65bc023 100644
--- a/build2/variable.cxx
+++ b/build2/variable.cxx
@@ -333,9 +333,11 @@ namespace build2
throw invalid_argument (string ());
}
+ constexpr const char* const value_traits<bool>::type_name = "bool";
+
const value_type value_traits<bool>::value_type
{
- "bool",
+ type_name,
sizeof (bool),
nullptr, // No base.
nullptr, // No dtor (POD).
@@ -371,9 +373,11 @@ namespace build2
throw invalid_argument (string ());
}
+ constexpr const char* const value_traits<uint64_t>::type_name = "uint64";
+
const value_type value_traits<uint64_t>::value_type
{
- "uint64",
+ type_name,
sizeof (uint64_t),
nullptr, // No base.
nullptr, // No dtor (POD).
@@ -455,9 +459,11 @@ namespace build2
return s;
}
+ constexpr const char* const value_traits<string>::type_name = "string";
+
const value_type value_traits<string>::value_type
{
- "string",
+ type_name,
sizeof (string),
nullptr, // No base.
&default_dtor<string>,
@@ -498,9 +504,11 @@ namespace build2
throw invalid_argument (string ());
}
+ constexpr const char* const value_traits<path>::type_name = "path";
+
const value_type value_traits<path>::value_type
{
- "path",
+ type_name,
sizeof (path),
nullptr, // No base.
&default_dtor<path>,
@@ -539,9 +547,11 @@ namespace build2
throw invalid_argument (string ());
}
+ constexpr const char* const value_traits<dir_path>::type_name = "dir_path";
+
const value_type value_traits<dir_path>::value_type
{
- "dir_path",
+ type_name,
sizeof (dir_path),
nullptr, // No base, or should it be path?
&default_dtor<dir_path>,
@@ -570,9 +580,12 @@ namespace build2
return abs_dir_path (move (d));
}
+ constexpr const char* const value_traits<abs_dir_path>::type_name =
+ "abs_dir_path";
+
const value_type value_traits<abs_dir_path>::value_type
{
- "abs_dir_path",
+ type_name,
sizeof (abs_dir_path),
&value_traits<dir_path>::value_type, // Assume direct cast works for both.
&default_dtor<abs_dir_path>,
@@ -603,9 +616,11 @@ namespace build2
return names_view (&v.as<name> (), 1);
}
+ constexpr const char* const value_traits<name>::type_name = "name";
+
const value_type value_traits<name>::value_type
{
- "name",
+ type_name,
sizeof (name),
nullptr, // No base.
&default_dtor<name>,
diff --git a/build2/variable.txx b/build2/variable.txx
index 31d9284..6d3121a 100644
--- a/build2/variable.txx
+++ b/build2/variable.txx
@@ -272,7 +272,7 @@ namespace build2
template <typename T>
const string value_traits<vector<T>>::type_name = string (
- value_traits<T>::value_type.name) + 's';
+ value_traits<T>::type_name) + 's';
template <typename T>
const value_type value_traits<vector<T>>::value_type
@@ -432,8 +432,8 @@ namespace build2
template <typename K, typename V>
const string value_traits<std::map<K, V>>::type_name = string (
- value_traits<K>::value_type.name) + '_' +
- value_traits<V>::value_type.name + "_map";
+ value_traits<K>::type_name) + '_' +
+ value_traits<V>::type_name + "_map";
template <typename K, typename V>
const value_type value_traits<std::map<K, V>>::value_type