diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 0e1d0395146..8b3c835caf3 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1539,9 +1539,10 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings, if (element && isStdVectorOrString()) { // isStdVectorOrString sets type token if true element = false; // not really an array element } else if (variableInfo->isEnumType()) { - if (variableInfo->type() && variableInfo->type()->classScope && variableInfo->type()->classScope->enumType) + const bool hasEnumType = variableInfo->type() && variableInfo->type()->classScope && variableInfo->type()->classScope->enumType; + if (hasEnumType && variableInfo->type()->classScope->enumType->isStandardType()) typeToken = variableInfo->type()->classScope->enumType; - else { + else if (!hasEnumType) { tempToken = new Token(tok1); tempToken->str("int"); typeToken = tempToken; diff --git a/test/testio.cpp b/test/testio.cpp index ec6a87a1e16..02180f12376 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -3371,6 +3371,20 @@ class TestIO : public TestFixture { "}"); ASSERT_EQUALS("", errout_str()); + check("enum E : uint8_t { E0 }; \n" // #7959 + "void f(E e) {\n" + " printf(\"%hhu\", e);\n" + "}"); + ASSERT_EQUALS("", errout_str()); + + check("enum E : uint8_t { E0 }; \n" + "void f(E e) {\n" + " printf(\"%lu\", e);\n" + "}"); + TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uint8_t'.\n", + "", + errout_str()); + check("void f() {\n" " printf(\"%lu\", sizeof(char));\n" "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));