From a15e25f9fe1a5891ea4a9afc2d52bc5e80f3c8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 24 Apr 2010 16:46:09 +0200 Subject: [PATCH] Fixed #1571 ('C-style pointer casting' should not be reported for C files) --- lib/checkother.cpp | 2 +- test/testother.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index aae43d771..82126afda 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -45,7 +45,7 @@ CheckOther instance; void CheckOther::warningOldStylePointerCast() { - if (!_settings->_checkCodingStyle) + if (!_settings->_checkCodingStyle || _tokenizer->fileLine(_tokenizer->tokens()).find(".cpp") == std::string::npos) return; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) diff --git a/test/testother.cpp b/test/testother.cpp index c2f450dde..ee30d1ab5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1993,10 +1993,15 @@ private: void checkOldStylePointerCast(const char code[]) { // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizerCpp; std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - tokenizer.setVarId(); + tokenizerCpp.tokenize(istr, "test.cpp"); + tokenizerCpp.setVarId(); + + Tokenizer tokenizerC; + std::istringstream istr2(code); + tokenizerC.tokenize(istr2, "test.c"); + tokenizerC.setVarId(); // Clear the error buffer.. errout.str(""); @@ -2004,8 +2009,12 @@ private: // Check for redundant code.. Settings settings; settings._checkCodingStyle = true; - CheckOther checkOther(&tokenizer, &settings, this); - checkOther.warningOldStylePointerCast(); + + CheckOther checkOtherCpp(&tokenizerCpp, &settings, this); + checkOtherCpp.warningOldStylePointerCast(); + + CheckOther checkOtherC(&tokenizerC, &settings, this); + checkOtherC.warningOldStylePointerCast(); } void oldStylePointerCast()