From be2bc1be5b34542e9609911ffcbc871e5443189e Mon Sep 17 00:00:00 2001 From: josetr <37419832+josetr@users.noreply.github.com> Date: Mon, 9 Nov 2020 13:08:29 +0000 Subject: [PATCH] Fix C4251 warnings (#1487) --- tests/CLI/CLI.h | 4 +++- tests/CSharp/CSharp.h | 12 +++++++++--- tests/CSharp/CSharpTemplates.h | 12 ++++++------ tests/Common/Common.h | 7 +++++-- tests/Encodings/Encodings.h | 5 ++++- tests/StandardLib/StandardLib.h | 26 ++++++++++++++------------ tests/Tests.h | 8 ++++++++ tests/VTables/VTables.h | 5 ++++- 8 files changed, 53 insertions(+), 26 deletions(-) diff --git a/tests/CLI/CLI.h b/tests/CLI/CLI.h index 0b70ac0a..fa64384a 100644 --- a/tests/CLI/CLI.h +++ b/tests/CLI/CLI.h @@ -70,7 +70,9 @@ public: TestMappedTypeNonConstRefParam(const std::string); const TestMappedTypeNonConstRefParam& operator=(const std::string); - std::string m_str; + DISABLE_WARNING_ONCE(4251, + std::string m_str; + ) }; class DLL_API TestMappedTypeNonConstRefParamConsumer diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 19eb8764..27c8c4a9 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -60,7 +60,10 @@ public: protected: int P; TemplateInAnotherUnit templateInAnotherUnit; - std::string _name; + + DISABLE_WARNING_ONCE(4251, + std::string _name; + ) }; class DLL_API Quux @@ -1121,13 +1124,16 @@ public: static const char Chr; static const unsigned char UChr; static const int Int; - static const float Float; - static const std::string String; + static const float Float; static const char ChrArray[2]; static const int IntArray[2]; static const float FloatArray[2]; static const bool BoolArray[2]; static const void* VoidPtrArray[2]; + + DISABLE_WARNING_ONCE(4251, + static const std::string String; + ) }; static constexpr double ConstexprCreateDoubleValue(double value) { diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index 12a2c71d..8a147c79 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -33,7 +33,7 @@ class DLL_API Ignored }; template -class IndependentFields : public T1 +class DLL_API IndependentFields : public T1 { typedef T Type; public: @@ -122,7 +122,7 @@ T IndependentFields::staticDependent(const T& t) template int IndependentFields::getIndependent() { - return independent; + return static_cast(independent); } template @@ -143,7 +143,7 @@ class Base }; template -class DependentValueFields : public Base +class DLL_API DependentValueFields : public Base { public: class Nested; @@ -248,7 +248,7 @@ public: }; template -class DependentPointerFields +class DLL_API DependentPointerFields { public: DependentPointerFields(T t = 0); @@ -318,7 +318,7 @@ void TwoTemplateArgs::takeDependentPtrToSecondTemplateArg(const V& v) } template > -class HasDefaultTemplateArgument +class DLL_API HasDefaultTemplateArgument { public: HasDefaultTemplateArgument(); @@ -688,7 +688,7 @@ enum class UsedInTemplatedIndexer }; template -class QFlags +class DLL_API QFlags { typedef int Int; typedef int (*Zero); diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 73e67b6f..963b4461 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -891,9 +891,12 @@ public: HasStdString(); ~HasStdString(); std::string testStdString(const std::string& s); - std::string testStdStringPassedByValue(std::string s); - std::string s; + std::string testStdStringPassedByValue(std::string s); std::string& getStdString(); + + DISABLE_WARNING_ONCE(4251, + std::string s; + ) }; class DLL_API InternalCtorAmbiguity diff --git a/tests/Encodings/Encodings.h b/tests/Encodings/Encodings.h index 9ab7efd4..21b91be7 100644 --- a/tests/Encodings/Encodings.h +++ b/tests/Encodings/Encodings.h @@ -4,11 +4,14 @@ class DLL_API Foo { public: + DISABLE_WARNING_ONCE(4251, + static std::string StringVariable; + ) + Foo(); ~Foo(); const char* Unicode; - static std::string StringVariable; // TODO: VC++ does not support char16 // char16 chr16; diff --git a/tests/StandardLib/StandardLib.h b/tests/StandardLib/StandardLib.h index 83102cd2..b49f517b 100644 --- a/tests/StandardLib/StandardLib.h +++ b/tests/StandardLib/StandardLib.h @@ -20,18 +20,20 @@ struct DLL_API TestVectors std::vector GetIntVector(); int SumIntVector(std::vector& vec); - // Should get mapped to List - std::vector IntVector; - // Should get mapped to List - std::vector IntPtrVector; - // Should get mapped to List - std::vector IntWrapperVector; - // Should get mapped to List - std::vector IntWrapperPtrVector; - // Should get mapped to List - std::vector IntWrapperValueTypeVector; - // Should get mapped to List - VectorTypedef IntWrapperValueTypeVectorTypedef; + DISABLE_WARNING_ONCE(4251, + // Should get mapped to List + std::vector IntVector; + // Should get mapped to List + std::vector IntPtrVector; + // Should get mapped to List + std::vector IntWrapperVector; + // Should get mapped to List + std::vector IntWrapperPtrVector; + // Should get mapped to List + std::vector IntWrapperValueTypeVector; + // Should get mapped to List + VectorTypedef IntWrapperValueTypeVectorTypedef; + ) }; struct DLL_API OStreamTest diff --git a/tests/Tests.h b/tests/Tests.h index 1a25174b..0197827d 100644 --- a/tests/Tests.h +++ b/tests/Tests.h @@ -20,6 +20,12 @@ #define THISCALL __thiscall #endif +#define DISABLE_WARNING_ONCE(id, block) \ +__pragma(warning(push)) \ +__pragma(warning(disable: id)) \ +block \ +__pragma(warning(pop)) + #else #define DLL_API __attribute__ ((visibility ("default"))) @@ -40,6 +46,8 @@ #define THISCALL #endif +#define DISABLE_WARNING_ONCE(id, block) block + #endif #define CS_OUT diff --git a/tests/VTables/VTables.h b/tests/VTables/VTables.h index 40fa8880..59304b03 100644 --- a/tests/VTables/VTables.h +++ b/tests/VTables/VTables.h @@ -17,7 +17,10 @@ public: virtual int append(); virtual int append(int a); int callVirtualWithParameter(int a); - std::string s; + + DISABLE_WARNING_ONCE(4251, + std::string s; + ) }; DLL_API int FooCallFoo(Foo* foo);