diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 66c0b3e30..0fb9ae662 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1140,6 +1140,10 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int continue; } + // skip sizeof / offsetof + if (Token::Match(tok, "sizeof|offsetof (")) + tok = tok->next()->link(); + // TODO: handle loops, try, etc if (tok->str() == "for" || Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) { return true; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b921e1cba..9af9e2f06 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1873,6 +1873,13 @@ private: " x++;\n" "}"); ASSERT_EQUALS("", errout.str()); + + // sizeof / offsetof + checkUninitVar2("void f() {\n" + " int i;\n" + " sizeof(i+1);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };