Skip to content

Commit

Permalink
Fixed #4608 (false positive: (style) struct or union member is never …
Browse files Browse the repository at this point in the history
…used.)
  • Loading branch information
danmar committed Mar 1, 2013
1 parent 4c23f01 commit d7a52ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions lib/path.cpp
Expand Up @@ -206,7 +206,13 @@ bool Path::isCPP(const std::string &path)
return(getFilenameExtension(path) == ".C"); 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);
} }
16 changes: 12 additions & 4 deletions lib/path.h
Expand Up @@ -104,24 +104,32 @@ class CPPCHECKLIB Path {
/** /**
* @brief Check if the file extension indicates that it's a C/C++ source file. * @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 * 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 * @return returns true if the file extension indicates it should be checked
*/ */
static bool acceptFile(const std::string &filename); static bool acceptFile(const std::string &filename);


/** /**
* @brief Identify language based on file extension. * @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 * @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. * @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 * @return true if extension is meant for C++ files
*/ */
static bool isCPP(const std::string &extensionInLowerCase); 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);
}; };


/// @} /// @}
Expand Down
4 changes: 4 additions & 0 deletions test/testpath.cpp
Expand Up @@ -74,6 +74,10 @@ class TestPath : public TestFixture {
ASSERT(Path::acceptFile("index")==false); ASSERT(Path::acceptFile("index")==false);
ASSERT(Path::acceptFile("")==false); ASSERT(Path::acceptFile("")==false);
ASSERT(Path::acceptFile("C")==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 { void getRelative() const {
Expand Down

0 comments on commit d7a52ea

Please sign in to comment.