From 5673348215d7cf566fd9d92d0db0d21314cf42ad Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Sun, 21 Jan 2018 01:26:37 -0500 Subject: [PATCH] Fixed #8350 (False positive: enum class static_cast to int is treated as non-primitive when type inference is used) (#1042) --- lib/checkpostfixoperator.h | 4 +++- test/testpostfixoperator.cpp | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index a993554a7..fe22749ce 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -50,13 +50,15 @@ public: : Check(myName(), tokenizer, settings, errorLogger) { } - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (tokenizer->isC()) return; CheckPostfixOperator checkPostfixOperator(tokenizer, settings, errorLogger); checkPostfixOperator.postfixOperator(); } + void runSimplifiedChecks(const Tokenizer * /*tokenizer*/, const Settings * /*settings*/, ErrorLogger * /*errorLogger*/) { + } /** Check postfix operators */ void postfixOperator(); diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 53498635c..d8043e448 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -40,7 +40,6 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList2(); // Check for postfix operators.. CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); @@ -59,6 +58,7 @@ private: TEST_CASE(testtemplate); // #4686 TEST_CASE(testmember); TEST_CASE(testcomma); + TEST_CASE(testauto); // #8350 } void testsimple() { @@ -352,6 +352,18 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void testauto() { // #8350 + check("enum class Color { Red = 0, Green = 1, };\n" + "int fun(const Color color) {\n" + " auto a = 0;\n" + " for (auto i = static_cast(color); i < 10; i++) {\n" + " a += i;\n" + " }\n" + " return a;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestPostfixOperator)