diff options
Diffstat (limited to 'include/llvm/Support/JSON.h')
| -rw-r--r-- | include/llvm/Support/JSON.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/llvm/Support/JSON.h b/include/llvm/Support/JSON.h index da3c5ea0b25d..7a04fd52bc50 100644 --- a/include/llvm/Support/JSON.h +++ b/include/llvm/Support/JSON.h @@ -294,9 +294,13 @@ public: Value(json::Array &&Elements) : Type(T_Array) { create<json::Array>(std::move(Elements)); } + template <typename Elt> + Value(const std::vector<Elt> &C) : Value(json::Array(C)) {} Value(json::Object &&Properties) : Type(T_Object) { create<json::Object>(std::move(Properties)); } + template <typename Elt> + Value(const std::map<std::string, Elt> &C) : Value(json::Object(C)) {} // Strings: types with value semantics. Must be valid UTF-8. Value(std::string V) : Type(T_String) { if (LLVM_UNLIKELY(!isUTF8(V))) { @@ -452,7 +456,10 @@ private: new (reinterpret_cast<T *>(Union.buffer)) T(std::forward<U>(V)...); } template <typename T> T &as() const { - return *reinterpret_cast<T *>(Union.buffer); + // Using this two-step static_cast via void * instead of reinterpret_cast + // silences a -Wstrict-aliasing false positive from GCC6 and earlier. + void *Storage = static_cast<void *>(Union.buffer); + return *static_cast<T *>(Storage); } template <typename Indenter> |
