From d7a52eaecdc55ba351125303c535ba774a4d33e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 1 Mar 2013 16:13:04 +0100 Subject: [PATCH] Fixed #4608 (false positive: (style) struct or union member is never used.) --- lib/path.cpp | 10 ++++++++-- lib/path.h | 16 ++++++++++++---- test/testpath.cpp | 4 ++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/path.cpp b/lib/path.cpp index 54e12b238..c697cc150 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -206,7 +206,13 @@ bool Path::isCPP(const std::string &path) return(getFilenameExtension(path) == ".C"); } -bool Path::acceptFile(const std::string &filename) +bool Path::acceptFile(const std::string &path) { - return(Path::isCPP(filename) || Path::isC(filename)); + return !Path::isHeader(path) && (Path::isCPP(path) || Path::isC(path)); +} + +bool Path::isHeader(const std::string &path) +{ + const std::string extension = getFilenameExtensionInLowerCase(path); + return (extension.compare(0, 2, ".h") == 0); } diff --git a/lib/path.h b/lib/path.h index c316c900b..cb8f8b608 100644 --- a/lib/path.h +++ b/lib/path.h @@ -104,24 +104,32 @@ public: /** * @brief Check if the file extension indicates that it's a C/C++ source file. * Check if the file has source file extension: *.c;*.cpp;*.cxx;*.c++;*.cc;*.txx - * @param filename filename to check + * @param path filename to check. path info is optional * @return returns true if the file extension indicates it should be checked */ static bool acceptFile(const std::string &filename); /** * @brief Identify language based on file extension. - * @param extensionInLowerCase e.g. ".c" + * @param path filename to check. path info is optional * @return true if extension is meant for C files */ - static bool isC(const std::string &extensionInLowerCase); + static bool isC(const std::string &path); /** * @brief Identify language based on file extension. - * @param extensionInLowerCase e.g. ".cpp" + * @param path filename to check. path info is optional * @return true if extension is meant for C++ files */ static bool isCPP(const std::string &extensionInLowerCase); + +private: + /** + * @brief Is filename a header based on file extension + * @param path filename to check. path info is optional + * @return true if filename extension is meant for headers + */ + static bool isHeader(const std::string &path); }; /// @} diff --git a/test/testpath.cpp b/test/testpath.cpp index 3fd57bb3d..07ffb7796 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -74,6 +74,10 @@ private: ASSERT(Path::acceptFile("index")==false); ASSERT(Path::acceptFile("")==false); ASSERT(Path::acceptFile("C")==false); + + // don't accept any headers + ASSERT_EQUALS(false, Path::acceptFile("index.h")); + ASSERT_EQUALS(false, Path::acceptFile("index.hpp")); } void getRelative() const {