diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 5dd06f282..1258edfab 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -317,6 +317,8 @@ void CheckSizeof::sizeofVoid() // Check for cast expression if (Token::simpleMatch(tok2->previous(), ")") && !Token::Match(tok2->previous()->link(), "( const| void *")) continue; + if (tok2->strAt(-1) == "&") // Check for reference operator + continue; } arithOperationsOnVoidPointerError(tok, varname, var->typeStartToken()->stringifyList(var->typeEndToken()->next())); diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 402a936a9..167dfa1bb 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -526,6 +526,13 @@ private: ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n" "[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str()); + check("void f() {\n" + " void* p = malloc(10);\n" + " int* p2 = &p + 4;\n" + " int* p3 = &p - 1;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " void** p1 = malloc(10);\n" " p1--;\n"