From efab840b50a62c84fa6c4ad74a4b85788e2ac95d Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 6 Sep 2014 13:09:02 +0200 Subject: [PATCH] #5230 Explicit reinterpret_cast should not give a warning. Lower all invalidPointerCast messages to 'portability' --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 62f69286a..c0cfacb8a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -481,7 +481,7 @@ void CheckOther::invalidPointerCast() std::string fromType = analyzeType(fromTok); std::string toType = analyzeType(toTok); - if (fromType != toType && !fromType.empty() && !toType.empty() && (toType != "integer" || _settings->isEnabled("portability")) && (toTok->str() != "char" || _settings->inconclusive)) + if (fromType != toType && !fromType.empty() && !toType.empty() && _settings->isEnabled("portability") && (toTok->str() != "char" || _settings->inconclusive)) invalidPointerCastError(tok, fromType, toType, toTok->str() == "char"); } } @@ -495,7 +495,7 @@ void CheckOther::invalidPointerCastError(const Token* tok, const std::string& fr else reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to char* is not portable due to different binary data representations on different platforms.", true); } else - reportError(tok, Severity::warning, "invalidPointerCast", "Casting between " + from + "* and " + to + "* which have an incompatible binary data representation."); + reportError(tok, Severity::portability, "invalidPointerCast", "Casting between " + from + "* and " + to + "* which have an incompatible binary data representation."); } //--------------------------------------------------------------------------- diff --git a/test/testother.cpp b/test/testother.cpp index 2b221dbdf..4e49a0cfd 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1198,7 +1198,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkInvalidPointerCast(const char code[], bool portability = false, bool inconclusive = false) { + void checkInvalidPointerCast(const char code[], bool portability = true, bool inconclusive = false) { // Clear the error buffer.. errout.str(""); @@ -1224,36 +1224,36 @@ private: " delete [] (double*)f;\n" " delete [] (long double const*)(new float[10]);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n" - "[test.cpp:4]: (warning) Casting between float* and long double* which have an incompatible binary data representation.\n", - "[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n" - "[test.cpp:4]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n" + "[test.cpp:4]: (portability) Casting between float* and long double* which have an incompatible binary data representation.\n", + "[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n" + "[test.cpp:4]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("void test(const float* f) {\n" " double *d = (double*)f;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("void test(double* d1) {\n" " long double *ld = (long double*)d1;\n" " double *d2 = (double*)ld;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and long double* which have an incompatible binary data representation.\n" - "[test.cpp:3]: (warning) Casting between long double* and double* which have an incompatible binary data representation.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between double* and long double* which have an incompatible binary data representation.\n" + "[test.cpp:3]: (portability) Casting between long double* and double* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("char* test(int* i) {\n" " long double *d = (long double*)(i);\n" " double *d = (double*)(i);\n" " float *f = reinterpret_cast(i);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and long double* which have an incompatible binary data representation.\n" - "[test.cpp:3]: (warning) Casting between integer* and double* which have an incompatible binary data representation.\n" - "[test.cpp:4]: (warning) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between integer* and long double* which have an incompatible binary data representation.\n" + "[test.cpp:3]: (portability) Casting between integer* and double* which have an incompatible binary data representation.\n" + "[test.cpp:4]: (portability) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i[0];\n" @@ -1263,7 +1263,7 @@ private: checkInvalidPointerCast("float* test(double& d) {\n" " return (float*)&d;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and float* which have an incompatible binary data representation.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between double* and float* which have an incompatible binary data representation.\n", errout.str()); checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n"