|
Packit |
2035a7 |
/*
|
|
Packit |
2035a7 |
* Cppcheck - A tool for static C/C++ code analysis
|
|
Packit |
2035a7 |
* Copyright (C) 2007-2017 Cppcheck team.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is free software: you can redistribute it and/or modify
|
|
Packit |
2035a7 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
2035a7 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit |
2035a7 |
* (at your option) any later version.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
2035a7 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
2035a7 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
2035a7 |
* GNU General Public License for more details.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
2035a7 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
//---------------------------------------------------------------------------
|
|
Packit |
2035a7 |
#ifndef checkboostH
|
|
Packit |
2035a7 |
#define checkboostH
|
|
Packit |
2035a7 |
//---------------------------------------------------------------------------
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include "check.h"
|
|
Packit |
2035a7 |
#include "config.h"
|
|
Packit |
2035a7 |
#include "tokenize.h"
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include <string>
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
class ErrorLogger;
|
|
Packit |
2035a7 |
class Settings;
|
|
Packit |
2035a7 |
class Token;
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/// @addtogroup Checks
|
|
Packit |
2035a7 |
/// @{
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** @brief %Check Boost usage */
|
|
Packit |
2035a7 |
class CPPCHECKLIB CheckBoost : public Check {
|
|
Packit |
2035a7 |
public:
|
|
Packit |
2035a7 |
/** This constructor is used when registering the CheckClass */
|
|
Packit |
2035a7 |
CheckBoost() : Check(myName()) {
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** This constructor is used when running checks. */
|
|
Packit |
2035a7 |
CheckBoost(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
|
Packit |
2035a7 |
: Check(myName(), tokenizer, settings, errorLogger) {
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** Simplified checks. The token list is simplified. */
|
|
Packit |
2035a7 |
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
|
Packit |
2035a7 |
if (!tokenizer->isCPP())
|
|
Packit |
2035a7 |
return;
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
CheckBoost checkBoost(tokenizer, settings, errorLogger);
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
checkBoost.checkBoostForeachModification();
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** @brief %Check for container modification while using the BOOST_FOREACH macro */
|
|
Packit |
2035a7 |
void checkBoostForeachModification();
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
private:
|
|
Packit |
2035a7 |
void boostForeachError(const Token *tok);
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
|
Packit |
2035a7 |
CheckBoost c(nullptr, settings, errorLogger);
|
|
Packit |
2035a7 |
c.boostForeachError(nullptr);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
static std::string myName() {
|
|
Packit |
2035a7 |
return "Boost usage";
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
std::string classInfo() const {
|
|
Packit |
2035a7 |
return "Check for invalid usage of Boost:\n"
|
|
Packit |
2035a7 |
"- container modification during BOOST_FOREACH\n";
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
};
|
|
Packit |
2035a7 |
/// @}
|
|
Packit |
2035a7 |
//---------------------------------------------------------------------------
|
|
Packit |
2035a7 |
#endif // checkboostH
|