Permalink
Browse files

Fixed #4608 (false positive: (style) struct or union member is never …

…used.)
  • Loading branch information...
danmar committed Mar 1, 2013
1 parent 4c23f01 commit d7a52eaecdc55ba351125303c535ba774a4d33e6
Showing with 24 additions and 6 deletions.
  1. +8 −2 lib/path.cpp
  2. +12 −4 lib/path.h
  3. +4 −0 test/testpath.cpp
View
@@ -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);
}
View
@@ -104,24 +104,32 @@ class CPPCHECKLIB Path {
/**
* @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);
};
/// @}
View
@@ -74,6 +74,10 @@ class TestPath : public TestFixture {
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 {

0 comments on commit d7a52ea

Please sign in to comment.