From 485f3c77087baa45c4430340614782cbc3534e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 6 Jan 2010 19:04:15 +0100 Subject: [PATCH] Fixed #1221 ([False positive] Member variable not initialized with operator[] gives wrong result) --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 595607579..b935e8915 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -165,7 +165,7 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo } // If the varname was set in one of the two if-block above, create a entry for this variable.. - if (varname) + if (varname && strcmp(varname, "operator")) { Var *var = new Var(varname, false, priv, varlist); varlist = var; diff --git a/test/testclass.cpp b/test/testclass.cpp index 64555969a..7986552ea 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -59,6 +59,7 @@ private: TEST_CASE(uninitVarHeader2); // Class is defined in header TEST_CASE(uninitVarHeader3); // Class is defined in header TEST_CASE(uninitVarPublished); // Variables in the published section are auto-initialized + TEST_CASE(uninitOperator); // No FP about uninitialized 'operator[]' TEST_CASE(noConstructor1); TEST_CASE(noConstructor2); @@ -67,10 +68,10 @@ private: TEST_CASE(operatorEq1); TEST_CASE(operatorEqRetRefThis); - TEST_CASE(operatorEqToSelf1); // single class - TEST_CASE(operatorEqToSelf2); // nested class - TEST_CASE(operatorEqToSelf3); // multiple inheritance - TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance + TEST_CASE(operatorEqToSelf1); // single class + TEST_CASE(operatorEqToSelf2); // nested class + TEST_CASE(operatorEqToSelf3); // multiple inheritance + TEST_CASE(operatorEqToSelf4); // nested class with multiple inheritance TEST_CASE(memsetOnStruct); TEST_CASE(memsetOnClass); @@ -1213,7 +1214,16 @@ private: ASSERT_EQUALS("", errout.str()); } - + void uninitOperator() + { + checkUninitVar("class Fred\n" + "{\n" + "public:\n" + " Fred() { }\n" + " int *operator [] (int index) { return 0; }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void checkNoConstructor(const char code[]) {