Skip to content

Commit

Permalink
Fix #13550 Remove boostForeachError/checkboost.cpp (#7198)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 13, 2025
1 parent 0e1166b commit 6ee9633
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 282 deletions.
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ LIBOBJ = $(libcppdir)/valueflow.o \
$(libcppdir)/checkassert.o \
$(libcppdir)/checkautovariables.o \
$(libcppdir)/checkbool.o \
$(libcppdir)/checkboost.o \
$(libcppdir)/checkbufferoverrun.o \
$(libcppdir)/checkclass.o \
$(libcppdir)/checkcondition.o \
Expand Down Expand Up @@ -275,7 +274,6 @@ TESTOBJ = test/fixture.o \
test/testastutils.o \
test/testautovariables.o \
test/testbool.o \
test/testboost.o \
test/testbufferoverrun.o \
test/testcharvar.o \
test/testcheck.o \
Expand Down Expand Up @@ -482,9 +480,6 @@ $(libcppdir)/checkautovariables.o: lib/checkautovariables.cpp lib/addoninfo.h li
$(libcppdir)/checkbool.o: lib/checkbool.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkbool.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkbool.cpp

$(libcppdir)/checkboost.o: lib/checkboost.cpp lib/check.h lib/checkboost.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkboost.cpp

$(libcppdir)/checkbufferoverrun.o: lib/checkbufferoverrun.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/astutils.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h lib/xml.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkbufferoverrun.cpp

Expand Down Expand Up @@ -719,9 +714,6 @@ test/testautovariables.o: test/testautovariables.cpp externals/simplecpp/simplec
test/testbool.o: test/testbool.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkbool.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testbool.cpp

test/testboost.o: test/testboost.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkboost.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testboost.cpp

test/testbufferoverrun.o: test/testbufferoverrun.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testbufferoverrun.cpp

Expand Down
82 changes: 0 additions & 82 deletions lib/checkboost.cpp

This file was deleted.

71 changes: 0 additions & 71 deletions lib/checkboost.h

This file was deleted.

2 changes: 0 additions & 2 deletions lib/cppcheck.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<ClCompile Include="checkassert.cpp" />
<ClCompile Include="checkautovariables.cpp" />
<ClCompile Include="checkbool.cpp" />
<ClCompile Include="checkboost.cpp" />
<ClCompile Include="checkbufferoverrun.cpp" />
<ClCompile Include="checkclass.cpp" />
<ClCompile Include="checkcondition.cpp" />
Expand Down Expand Up @@ -108,7 +107,6 @@
<ClInclude Include="checkassert.h" />
<ClInclude Include="checkautovariables.h" />
<ClInclude Include="checkbool.h" />
<ClInclude Include="checkboost.h" />
<ClInclude Include="checkbufferoverrun.h" />
<ClInclude Include="checkclass.h" />
<ClInclude Include="checkcondition.h" />
Expand Down
6 changes: 0 additions & 6 deletions lib/cppcheck.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@
<ClCompile Include="token.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="checkboost.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="checkinternal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -382,9 +379,6 @@
<ClInclude Include="checkautovariables.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="checkboost.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="checkio.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
7 changes: 4 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5499,10 +5499,11 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])

// if MACRO
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "if|for|while|BOOST_FOREACH %name% (")) {
if (Token::Match(tok, "if|for|while %name% (")) {
if (Token::simpleMatch(tok, "for each")) {
// 'for each ( )' -> 'asm ( )'
tok->str("asm");
// 'for each (x in y )' -> 'for (x : y)'
if (Token* in = Token::findsimplematch(tok->tokAt(2), "in", tok->linkAt(2)))
in->str(":");
tok->deleteNext();
} else if (tok->strAt(1) == "constexpr") {
tok->deleteNext();
Expand Down
4 changes: 0 additions & 4 deletions oss-fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ LIBOBJ = $(libcppdir)/valueflow.o \
$(libcppdir)/checkassert.o \
$(libcppdir)/checkautovariables.o \
$(libcppdir)/checkbool.o \
$(libcppdir)/checkboost.o \
$(libcppdir)/checkbufferoverrun.o \
$(libcppdir)/checkclass.o \
$(libcppdir)/checkcondition.o \
Expand Down Expand Up @@ -178,9 +177,6 @@ $(libcppdir)/checkautovariables.o: ../lib/checkautovariables.cpp ../lib/addoninf
$(libcppdir)/checkbool.o: ../lib/checkbool.cpp ../lib/addoninfo.h ../lib/astutils.h ../lib/check.h ../lib/checkbool.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkbool.cpp

$(libcppdir)/checkboost.o: ../lib/checkboost.cpp ../lib/check.h ../lib/checkboost.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkboost.cpp

$(libcppdir)/checkbufferoverrun.o: ../lib/checkbufferoverrun.cpp ../externals/tinyxml2/tinyxml2.h ../lib/addoninfo.h ../lib/astutils.h ../lib/check.h ../lib/checkbufferoverrun.h ../lib/color.h ../lib/config.h ../lib/ctu.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueflow.h ../lib/vfvalue.h ../lib/xml.h
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkbufferoverrun.cpp

Expand Down
56 changes: 55 additions & 1 deletion test/cfg/boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <boost/thread/lock_guard.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/core/scoped_enum.hpp>
#include <boost/foreach.hpp>

#include <set>
#include <vector>

BOOST_FORCEINLINE void boost_forceinline_test()
{}
Expand Down Expand Up @@ -108,6 +112,56 @@ void lock_guard_finiteLifetime(boost::mutex& m)
boost::lock_guard<boost::mutex>{ m };
}

void test_BOOST_FOREACH_1(std::vector<int> data)
{
BOOST_FOREACH(int i, data) {
// cppcheck-suppress invalidContainerLoop
data.push_back(123);
}
}

void test_BOOST_FOREACH_2(std::set<int> data)
{
BOOST_FOREACH(int i, data) {
// don't warn for std::set
data.insert(123);
}
}

void test_BOOST_FOREACH_3(std::vector<int> data)
{
BOOST_FOREACH(const int& i, data) {
// cppcheck-suppress invalidContainerLoop
data.erase(data.begin());
}
}

// Check single line usage
void test_BOOST_FOREACH_4(std::vector<int> data)
{
BOOST_FOREACH(const int& i, data)
// cppcheck-suppress invalidContainerLoop
data.clear();
}

// Container returned as result of a function -> Be quiet
std::vector<int> get_data();
void test_BOOST_FOREACH_5()
{
std::set<int> data;
BOOST_FOREACH(const int& i, get_data())
data.insert(i);
}

// Break after modification (#4788)
void test_BOOST_FOREACH_6(std::vector<int> data)
{
BOOST_FOREACH(int i, data) {
data.push_back(123);
break;
}
}

BOOST_AUTO_TEST_SUITE(my_auto_test_suite)

BOOST_AUTO_TEST_CASE(test_message_macros)
Expand All @@ -127,4 +181,4 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(my_tuple_test, T, test_types_w_tuples)
BOOST_TEST(sizeof(T) == 4U);
}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
Loading

0 comments on commit 6ee9633

Please sign in to comment.