#5230 Explicit reinterpret_cast should not give a warning. Lower all invalidPointerCast messages to 'portability'

This commit is contained in:
Alexander Mai 2014-09-06 13:09:02 +02:00
parent 29b46cb505
commit efab840b50
2 changed files with 15 additions and 15 deletions

View File

@ -481,7 +481,7 @@ void CheckOther::invalidPointerCast()
std::string fromType = analyzeType(fromTok); std::string fromType = analyzeType(fromTok);
std::string toType = analyzeType(toTok); 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"); invalidPointerCastError(tok, fromType, toType, toTok->str() == "char");
} }
} }
@ -495,7 +495,7 @@ void CheckOther::invalidPointerCastError(const Token* tok, const std::string& fr
else else
reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to char* is not portable due to different binary data representations on different platforms.", true); reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to char* is not portable due to different binary data representations on different platforms.", true);
} else } 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.");
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -1198,7 +1198,7 @@ private:
ASSERT_EQUALS("", errout.str()); 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.. // Clear the error buffer..
errout.str(""); errout.str("");
@ -1224,36 +1224,36 @@ private:
" delete [] (double*)f;\n" " delete [] (double*)f;\n"
" delete [] (long double const*)(new float[10]);\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" TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) 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:4]: (portability) 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:3]: (portability) 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()); "[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" checkInvalidPointerCast("void test(const float* f) {\n"
" double *d = (double*)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" checkInvalidPointerCast("void test(double* d1) {\n"
" long double *ld = (long double*)d1;\n" " long double *ld = (long double*)d1;\n"
" double *d2 = (double*)ld;\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" ASSERT_EQUALS("[test.cpp:2]: (portability) 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()); "[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" checkInvalidPointerCast("char* test(int* i) {\n"
" long double *d = (long double*)(i);\n" " long double *d = (long double*)(i);\n"
" double *d = (double*)(i);\n" " double *d = (double*)(i);\n"
" float *f = reinterpret_cast<float*>(i);\n" " float *f = reinterpret_cast<float*>(i);\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and long double* which have an incompatible binary data representation.\n" ASSERT_EQUALS("[test.cpp:2]: (portability) 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:3]: (portability) 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()); "[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" checkInvalidPointerCast("float* test(unsigned int* i) {\n"
" return (float*)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" checkInvalidPointerCast("float* test(unsigned int* i) {\n"
" return (float*)i[0];\n" " return (float*)i[0];\n"
@ -1263,7 +1263,7 @@ private:
checkInvalidPointerCast("float* test(double& d) {\n" checkInvalidPointerCast("float* test(double& d) {\n"
" return (float*)&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" checkInvalidPointerCast("void test(float* data) {\n"
" f.write((char*)data,sizeof(float));\n" " f.write((char*)data,sizeof(float));\n"