Skip to content

Commit

Permalink
Disable the msvc warning about unexported template specializations
Browse files Browse the repository at this point in the history
The warning is essentially a bug in msvc because it's harmless and requires exporting all accessible template specializations. See also http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Nov 25, 2020
1 parent 8a3a8bc commit 25b9082
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 54 deletions.
4 changes: 1 addition & 3 deletions tests/CLI/CLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ class DLL_API TestMappedTypeNonConstRefParam
TestMappedTypeNonConstRefParam(const std::string);
const TestMappedTypeNonConstRefParam& operator=(const std::string);

DISABLE_WARNING_ONCE(4251,
std::string m_str;
)
std::string m_str;
};

class DLL_API TestMappedTypeNonConstRefParamConsumer
Expand Down
12 changes: 3 additions & 9 deletions tests/CSharp/CSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ class DLL_API Foo
protected:
int P;
TemplateInAnotherUnit<int> templateInAnotherUnit;

DISABLE_WARNING_ONCE(4251,
std::string _name;
)
std::string _name;
};

class DLL_API Quux
Expand Down Expand Up @@ -1124,16 +1121,13 @@ class DLL_API StaticVariables {
static const char Chr;
static const unsigned char UChr;
static const int Int;
static const float Float;
static const float Float;
static const std::string String;
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) {
Expand Down
16 changes: 8 additions & 8 deletions tests/CSharp/CSharpTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DLL_API Ignored
};

template <typename T>
class DLL_API IndependentFields : public T1
class IndependentFields : public T1
{
typedef T Type;
public:
Expand All @@ -45,7 +45,7 @@ class DLL_API IndependentFields : public T1
IndependentFields(float f);
~IndependentFields();
explicit IndependentFields(const std::map<T, T> &other);
int getIndependent();
float getIndependent();
T getDependent(const T& t);
Type property();
static T staticDependent(const T& t);
Expand Down Expand Up @@ -120,9 +120,9 @@ T IndependentFields<T>::staticDependent(const T& t)
}

template <typename T>
int IndependentFields<T>::getIndependent()
float IndependentFields<T>::getIndependent()
{
return static_cast<int>(independent);
return independent;
}

template <typename X>
Expand All @@ -143,7 +143,7 @@ class Base
};

template <typename T>
class DLL_API DependentValueFields : public Base<T>
class DependentValueFields : public Base<T>
{
public:
class Nested;
Expand Down Expand Up @@ -248,7 +248,7 @@ class DLL_API DerivedFromSpecializationOfUnsupportedTemplate : public DependentV
};

template <typename T>
class DLL_API DependentPointerFields
class DependentPointerFields
{
public:
DependentPointerFields(T t = 0);
Expand Down Expand Up @@ -318,7 +318,7 @@ void TwoTemplateArgs<K, V>::takeDependentPtrToSecondTemplateArg(const V& v)
}

template <typename T, typename D = IndependentFields<T>>
class DLL_API HasDefaultTemplateArgument
class HasDefaultTemplateArgument
{
public:
HasDefaultTemplateArgument();
Expand Down Expand Up @@ -688,7 +688,7 @@ enum class UsedInTemplatedIndexer
};

template <typename T>
class DLL_API QFlags
class QFlags
{
typedef int Int;
typedef int (*Zero);
Expand Down
7 changes: 2 additions & 5 deletions tests/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,9 @@ class DLL_API HasStdString
HasStdString();
~HasStdString();
std::string testStdString(const std::string& s);
std::string testStdStringPassedByValue(std::string s);
std::string testStdStringPassedByValue(std::string s);
std::string s;
std::string& getStdString();

DISABLE_WARNING_ONCE(4251,
std::string s;
)
};

class DLL_API InternalCtorAmbiguity
Expand Down
5 changes: 1 addition & 4 deletions tests/Encodings/Encodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
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;
Expand Down
26 changes: 12 additions & 14 deletions tests/StandardLib/StandardLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ struct DLL_API TestVectors
std::vector<int> GetIntVector();
int SumIntVector(std::vector<int>& vec);

DISABLE_WARNING_ONCE(4251,
// Should get mapped to List<int>
std::vector<int> IntVector;
// Should get mapped to List<IntPtr>
std::vector<int*> IntPtrVector;
// Should get mapped to List<IntWrapper>
std::vector<IntWrapper> IntWrapperVector;
// Should get mapped to List<IntWrapper>
std::vector<IntWrapper*> IntWrapperPtrVector;
// Should get mapped to List<IntWrapperValueType>
std::vector<IntWrapperValueType> IntWrapperValueTypeVector;
// Should get mapped to List<IntWrapperValueType>
VectorTypedef IntWrapperValueTypeVectorTypedef;
)
// Should get mapped to List<int>
std::vector<int> IntVector;
// Should get mapped to List<IntPtr>
std::vector<int*> IntPtrVector;
// Should get mapped to List<IntWrapper>
std::vector<IntWrapper> IntWrapperVector;
// Should get mapped to List<IntWrapper>
std::vector<IntWrapper*> IntWrapperPtrVector;
// Should get mapped to List<IntWrapperValueType>
std::vector<IntWrapperValueType> IntWrapperValueTypeVector;
// Should get mapped to List<IntWrapperValueType>
VectorTypedef IntWrapperValueTypeVectorTypedef;
};

struct DLL_API OStreamTest
Expand Down
10 changes: 3 additions & 7 deletions tests/Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
#define THISCALL __thiscall
#endif

#define DISABLE_WARNING_ONCE(id, block) \
__pragma(warning(push)) \
__pragma(warning(disable: id)) \
block \
__pragma(warning(pop))
// HACK: work around https://developercommunity.visualstudio.com/content/problem/1269158/c4251-shown-for-any-not-explicitly-exported-templa.html
// harmless and requires exporting all template specializations
#pragma warning (disable : 4251 )

#else
#define DLL_API __attribute__ ((visibility ("default")))
Expand All @@ -46,8 +44,6 @@ __pragma(warning(pop))
#define THISCALL
#endif

#define DISABLE_WARNING_ONCE(id, block) block

#endif

#define CS_OUT
Expand Down
5 changes: 1 addition & 4 deletions tests/VTables/VTables.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class DLL_API Foo
virtual int append();
virtual int append(int a);
int callVirtualWithParameter(int a);

DISABLE_WARNING_ONCE(4251,
std::string s;
)
std::string s;
};

DLL_API int FooCallFoo(Foo* foo);
Expand Down

0 comments on commit 25b9082

Please sign in to comment.