From fc00bcfe0a27b8d6df66a98278bc9f53811daf7f Mon Sep 17 00:00:00 2001 From: Alex Fuller Date: Tue, 16 Sep 2025 08:39:20 +1000 Subject: [PATCH] Make templates compatible with clang-cl --- source/MaterialXCore/Library.h | 4 ++-- source/MaterialXCore/Value.cpp | 18 +++++++++--------- source/MaterialXCore/Value.h | 26 +++++++++++++------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/source/MaterialXCore/Library.h b/source/MaterialXCore/Library.h index 55c1a44557..e13f10d59d 100644 --- a/source/MaterialXCore/Library.h +++ b/source/MaterialXCore/Library.h @@ -35,8 +35,8 @@ #pragma warning(disable : 4661) #define MATERIALX_SYMBOL_EXPORT __declspec(dllexport) #define MATERIALX_SYMBOL_IMPORT __declspec(dllimport) - #define MATERIALX_EXPORT_EXTERN_TEMPLATE(...) template class MATERIALX_SYMBOL_EXPORT __VA_ARGS__ - #define MATERIALX_IMPORT_EXTERN_TEMPLATE(...) extern template class MATERIALX_SYMBOL_IMPORT __VA_ARGS__ + #define MATERIALX_EXPORT_EXTERN_TEMPLATE(...) template class __VA_ARGS__ + #define MATERIALX_IMPORT_EXTERN_TEMPLATE(...) extern template class __VA_ARGS__ #else #define MATERIALX_SYMBOL_EXPORT __attribute__((__visibility__("default"))) #define MATERIALX_SYMBOL_IMPORT __attribute__((__visibility__("default"))) diff --git a/source/MaterialXCore/Value.cpp b/source/MaterialXCore/Value.cpp index c66808e4ef..981e7847f4 100644 --- a/source/MaterialXCore/Value.cpp +++ b/source/MaterialXCore/Value.cpp @@ -449,15 +449,15 @@ template class ValueRegistry // Template instantiations // -#define INSTANTIATE_TYPE(T, name) \ - template <> const string TypedValue::TYPE = name; \ - template <> const string& TypedValue::getTypeString() const { return TYPE; } \ - template <> string TypedValue::getValueString() const { return toValueString(_data); } \ - template MX_CORE_API bool Value::isA() const; \ - template MX_CORE_API const T& Value::asA() const; \ - template MX_CORE_API const string& getTypeString(); \ - template MX_CORE_API string toValueString(const T& data); \ - template MX_CORE_API T fromValueString(const string& value); \ +#define INSTANTIATE_TYPE(T, name) \ + template <> MX_CORE_API const string TypedValue::TYPE = name; \ + template <> MX_CORE_API const string& TypedValue::getTypeString() const { return TYPE; } \ + template <> MX_CORE_API string TypedValue::getValueString() const { return toValueString(_data); } \ + template MX_CORE_API bool Value::isA() const; \ + template MX_CORE_API const T& Value::asA() const; \ + template MX_CORE_API const string& getTypeString(); \ + template MX_CORE_API string toValueString(const T& data); \ + template MX_CORE_API T fromValueString(const string& value); \ ValueRegistry registry##T; // Base types diff --git a/source/MaterialXCore/Value.h b/source/MaterialXCore/Value.h index a35ec4c989..fceff4c467 100644 --- a/source/MaterialXCore/Value.h +++ b/source/MaterialXCore/Value.h @@ -124,51 +124,51 @@ class MX_CORE_API Value }; /// The class template for typed subclasses of Value -template class MX_CORE_API TypedValue : public Value +template class TypedValue : public Value { public: - TypedValue() : + MX_CORE_API TypedValue() : _data{} { } - explicit TypedValue(const T& value) : + MX_CORE_API explicit TypedValue(const T& value) : _data(value) { } - virtual ~TypedValue() { } + MX_CORE_API virtual ~TypedValue() { } /// Create a deep copy of the value. - ValuePtr copy() const override + MX_CORE_API ValuePtr copy() const override { return Value::createValue(_data); } /// Set stored data object. - void setData(const T& value) + MX_CORE_API void setData(const T& value) { _data = value; } /// Set stored data object. - void setData(const TypedValue& value) + MX_CORE_API void setData(const TypedValue& value) { _data = value._data; } /// Return stored data object. - const T& getData() const + MX_CORE_API const T& getData() const { return _data; } /// Return type string. - const string& getTypeString() const override; + MX_CORE_API const string& getTypeString() const override; /// Return value string. - string getValueString() const override; + MX_CORE_API string getValueString() const override; // Returns true if value data matches. - bool isEqual(ConstValuePtr other) const override + MX_CORE_API bool isEqual(ConstValuePtr other) const override { if (!other || !other->isA()) { @@ -184,10 +184,10 @@ template class MX_CORE_API TypedValue : public Value /// Create a new value of this type from a value string. /// @return A shared pointer to a typed value, or an empty shared pointer /// if the conversion to the given data type cannot be performed. - static ValuePtr createFromString(const string& value); + MX_CORE_API static ValuePtr createFromString(const string& value); public: - static const string TYPE; + MX_CORE_API static const string TYPE; private: T _data;