diff --git a/.github/workflows/CI-cygwin.yml b/.github/workflows/CI-cygwin.yml
index b9ea30470da..fe9dcc65445 100644
--- a/.github/workflows/CI-cygwin.yml
+++ b/.github/workflows/CI-cygwin.yml
@@ -1,7 +1,5 @@
-# Some convenient links:
-# - https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
-#
-
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: CI-cygwin
on:
@@ -34,6 +32,7 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
+ if: false # the hard-coded cygwin repository has changed so the setup step fails - TODO: re-enable
steps:
- uses: actions/checkout@v3
diff --git a/.github/workflows/CI-mingw.yml b/.github/workflows/CI-mingw.yml
index 6a1b8fde64c..04145d72f89 100644
--- a/.github/workflows/CI-mingw.yml
+++ b/.github/workflows/CI-mingw.yml
@@ -1,7 +1,5 @@
-# Some convenient links:
-# - https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
-#
-
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: CI-mingw
on:
diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml
index 53458b87701..3d0db730702 100644
--- a/.github/workflows/CI-windows.yml
+++ b/.github/workflows/CI-windows.yml
@@ -1,7 +1,5 @@
-# Some convenient links:
-# - https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
-#
-
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: CI-windows
on:
diff --git a/.github/workflows/buildman.yml b/.github/workflows/buildman.yml
index cb7fc655bee..1d6804715f2 100644
--- a/.github/workflows/buildman.yml
+++ b/.github/workflows/buildman.yml
@@ -1,3 +1,5 @@
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: Build manual
on:
diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml
index 19c40de61c9..cfc3bc12966 100644
--- a/.github/workflows/cifuzz.yml
+++ b/.github/workflows/cifuzz.yml
@@ -1,8 +1,16 @@
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: CIFuzz
+
on: [pull_request]
+
+permissions:
+ contents: read
+
jobs:
Fuzzing:
runs-on: ubuntu-latest
+ if: ${{ github.repository_owner == 'danmar' }}
steps:
- name: Build Fuzzers
id: build
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index f486cf9e24f..d553598cfc8 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -1,3 +1,5 @@
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: "CodeQL"
on:
diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml
index 9dad4d443f3..148fc15462d 100644
--- a/.github/workflows/coverity.yml
+++ b/.github/workflows/coverity.yml
@@ -1,4 +1,5 @@
-
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: Coverity
on:
diff --git a/.github/workflows/cppcheck-premium.yml b/.github/workflows/cppcheck-premium.yml
index 9604d29542a..a9b40184726 100644
--- a/.github/workflows/cppcheck-premium.yml
+++ b/.github/workflows/cppcheck-premium.yml
@@ -1,4 +1,5 @@
-
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: cppcheck-premium
on:
diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml
index a4c2c2a638f..4bcd3eceb58 100644
--- a/.github/workflows/iwyu.yml
+++ b/.github/workflows/iwyu.yml
@@ -18,6 +18,7 @@ jobs:
image: ["opensuse/tumbleweed:latest"] # "fedora:latest" / "debian:unstable" / "archlinux:latest"
runs-on: ubuntu-22.04
+ if: ${{ github.repository_owner == 'danmar' }}
container:
image: ${{ matrix.image }}
@@ -118,6 +119,7 @@ jobs:
clang-include-cleaner:
runs-on: ubuntu-22.04
+ if: ${{ github.repository_owner == 'danmar' }}
env:
QT_VERSION: 5.15.2
diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml
index f10a67eaed2..ca4bbac67d8 100644
--- a/.github/workflows/release-windows.yml
+++ b/.github/workflows/release-windows.yml
@@ -1,7 +1,5 @@
-# Some convenient links:
-# - https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
-#
-
+# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
+# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: release-windows
on:
@@ -24,6 +22,7 @@ jobs:
build:
runs-on: windows-2022
+ if: ${{ github.repository_owner == 'danmar' }}
env:
# see https://www.pcre.org/original/changelog.txt
diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml
index 8ace8797f25..0cabb7b2271 100644
--- a/.github/workflows/tsan.yml
+++ b/.github/workflows/tsan.yml
@@ -67,7 +67,7 @@ jobs:
- name: CMake
run: |
- cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DUSE_THREADS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
+ cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
CC: clang-18
CXX: clang++-18
@@ -98,6 +98,8 @@ jobs:
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
+ env:
+ TEST_CPPCHECK_INJECT_EXECUTOR: thread
- name: Run test/cli (-j2)
run: |
@@ -129,6 +131,7 @@ jobs:
if: false
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5_summary -D__GNUC__ --error-exitcode=0 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=gnu --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings --check-level=exhaustive"
+ selfcheck_options="$selfcheck_options --executor=thread"
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options externals/simplecpp || ec=1
diff --git a/Makefile b/Makefile
index 314bf5c4e66..23a15c49e54 100644
--- a/Makefile
+++ b/Makefile
@@ -856,10 +856,10 @@ test/testtoken.o: test/testtoken.cpp lib/addoninfo.h lib/check.h lib/color.h lib
test/testtokenize.o: test/testtokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.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/templatesimplifier.h lib/token.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/testtokenize.cpp
-test/testtokenlist.o: test/testtokenlist.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
+test/testtokenlist.o: test/testtokenlist.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.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/testtokenlist.cpp
-test/testtokenrange.o: test/testtokenrange.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.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/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h
+test/testtokenrange.o: test/testtokenrange.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.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/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenrange.cpp
test/testtype.o: test/testtype.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checktype.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 lib/vfvalue.h test/fixture.h test/helpers.h
diff --git a/cfg/posix.cfg b/cfg/posix.cfg
index 1a90eea0963..24dc3656af4 100644
--- a/cfg/posix.cfg
+++ b/cfg/posix.cfg
@@ -5237,7 +5237,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
-
+
diff --git a/cfg/wxwidgets.cfg b/cfg/wxwidgets.cfg
index 5a9d44e5929..2f0cf5a1528 100644
--- a/cfg/wxwidgets.cfg
+++ b/cfg/wxwidgets.cfg
@@ -7365,6 +7365,26 @@
Use 'wxStyledTextEvent::GetString()' instead.
+
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
@@ -7409,9 +7429,18 @@
false
+
This function is deprecated and kept mostly for backwards compatibility. Please override 'GetMargins()' method instead in any new code.
+
+
+ false
+
+
+
+
+
@@ -14265,6 +14294,26 @@ wxItemKind kind = wxITEM_NORMAL) -->
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
false
@@ -14289,6 +14338,24 @@ wxItemKind kind = wxITEM_NORMAL) -->
+
+
+
+ false
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
@@ -14308,8 +14375,7 @@ wxItemKind kind = wxITEM_NORMAL) -->
false
-
-
+
@@ -16812,9 +16878,10 @@ wxItemKind kind = wxITEM_NORMAL) -->
+
-
+
false
diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp
index 15e2492d609..7f275ab00df 100644
--- a/cli/cmdlineparser.cpp
+++ b/cli/cmdlineparser.cpp
@@ -374,6 +374,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
ImportProject project;
+ bool executorAuto = true;
int8_t logMissingInclude{0};
for (int i = 1; i < argc; i++) {
@@ -614,6 +615,36 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
#endif
}
+ else if (std::strncmp(argv[i], "--executor=", 11) == 0) {
+ const std::string type = 11 + argv[i];
+ if (type == "auto") {
+ executorAuto = true;
+ mSettings.executor = Settings::defaultExecutor();
+ }
+ else if (type == "thread") {
+#if defined(HAS_THREADING_MODEL_THREAD)
+ executorAuto = false;
+ mSettings.executor = Settings::ExecutorType::Thread;
+#else
+ mLogger.printError("executor type 'thread' cannot be used as Cppcheck has not been built with a respective threading model.");
+ return Result::Fail;
+#endif
+ }
+ else if (type == "process") {
+#if defined(HAS_THREADING_MODEL_FORK)
+ executorAuto = false;
+ mSettings.executor = Settings::ExecutorType::Process;
+#else
+ mLogger.printError("executor type 'process' cannot be used as Cppcheck has not been built with a respective threading model.");
+ return Result::Fail;
+#endif
+ }
+ else {
+ mLogger.printError("unknown executor: '" + type + "'.");
+ return Result::Fail;
+ }
+ }
+
// Filter errors
else if (std::strncmp(argv[i], "--exitcode-suppressions=", 24) == 0) {
// exitcode-suppressions=filename.txt
@@ -751,7 +782,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}
else if (std::strncmp(argv[i], "-l", 2) == 0) {
-#ifdef THREADING_MODEL_FORK
+#ifdef HAS_THREADING_MODEL_FORK
std::string numberString;
// "-l 3"
@@ -1276,6 +1307,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
if (!loadCppcheckCfg())
return Result::Fail;
+ // TODO: bail out?
+ if (!executorAuto && mSettings.useSingleJob())
+ mLogger.printMessage("'--executor' has no effect as only a single job will be used.");
+
// Default template format..
if (mSettings.templateFormat.empty()) {
mSettings.templateFormat = "{bold}{file}:{line}:{column}: {red}{inconclusive:{magenta}}{severity}:{inconclusive: inconclusive:}{default} {message} [{id}]{reset}\\n{code}";
diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp
index b734077ca6c..7bebf81e5da 100644
--- a/cli/cppcheckexecutor.cpp
+++ b/cli/cppcheckexecutor.cpp
@@ -33,9 +33,10 @@
#include "suppressions.h"
#include "utils.h"
-#if defined(THREADING_MODEL_THREAD)
+#if defined(HAS_THREADING_MODEL_THREAD)
#include "threadexecutor.h"
-#elif defined(THREADING_MODEL_FORK)
+#endif
+#if defined(HAS_THREADING_MODEL_FORK)
#include "processexecutor.h"
#endif
@@ -271,18 +272,24 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
cppcheck.settings() = settings; // this is a copy
auto& suppressions = cppcheck.settings().supprs.nomsg;
- unsigned int returnValue;
+ unsigned int returnValue = 0;
if (settings.useSingleJob()) {
// Single process
SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, suppressions, stdLogger);
returnValue = executor.check();
} else {
-#if defined(THREADING_MODEL_THREAD)
- ThreadExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
-#elif defined(THREADING_MODEL_FORK)
- ProcessExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
+#if defined(HAS_THREADING_MODEL_THREAD)
+ if (settings.executor == Settings::ExecutorType::Thread) {
+ ThreadExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
+ returnValue = executor.check();
+ }
+#endif
+#if defined(HAS_THREADING_MODEL_FORK)
+ if (settings.executor == Settings::ExecutorType::Process) {
+ ProcessExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
+ returnValue = executor.check();
+ }
#endif
- returnValue = executor.check();
}
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);
diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake
index 8ff3ba1d432..f4cb59f3bbc 100644
--- a/cmake/compilerDefinitions.cmake
+++ b/cmake/compilerDefinitions.cmake
@@ -41,8 +41,8 @@ if (ENABLE_CHECK_INTERNAL)
add_definitions(-DCHECK_INTERNAL)
endif()
-if (USE_THREADS)
- add_definitions(-DUSE_THREADS)
+if (DISALLOW_THREAD_EXECUTOR)
+ add_definitions(-DDISALLOW_THREAD_EXECUTOR)
endif()
if (MSVC AND DISABLE_CRTDBG_MAP_ALLOC)
diff --git a/cmake/options.cmake b/cmake/options.cmake
index 3e3b37f7a6e..d63d67079af 100644
--- a/cmake/options.cmake
+++ b/cmake/options.cmake
@@ -58,10 +58,14 @@ if (BUILD_CORE_DLL)
set(USE_BUNDLED_TINYXML2 ON)
endif()
option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON)
-option(USE_THREADS "Usage of threads instead of fork() for -j" OFF)
+option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j" OFF)
option(USE_BOOST "Usage of Boost" OFF)
option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
+if (DISALLOW_THREAD_EXECUTOR AND WIN32)
+ message(FATAL_ERROR "Cannot disable usage of ThreadExecutor on Windows as no other executor implementation is currently available")
+endif()
+
option(DISABLE_CRTDBG_MAP_ALLOC "Disable usage of Visual Studio C++ memory leak detection in Debug build" OFF)
option(NO_UNIX_SIGNAL_HANDLING "Disable usage of Unix Signal Handling" OFF)
option(NO_UNIX_BACKTRACE_SUPPORT "Disable usage of Unix Backtrace support" OFF)
diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake
index 77b9f997946..244c6b1e6bf 100644
--- a/cmake/printInfo.cmake
+++ b/cmake/printInfo.cmake
@@ -71,7 +71,7 @@ if (HAVE_RULES)
message( STATUS "PCRE_LIBRARY = ${PCRE_LIBRARY}" )
endif()
message( STATUS )
-message( STATUS "USE_THREADS = ${USE_THREADS}" )
+message( STATUS "DISALLOW_THREAD_EXECUTOR = ${DISALLOW_THREAD_EXECUTOR}" )
message( STATUS "CMAKE_THREAD_LIBS_INIT = ${CMAKE_THREAD_LIBS_INIT}" )
message( STATUS )
message( STATUS "USE_BUNDLED_TINYXML2 = ${USE_BUNDLED_TINYXML2}" )
diff --git a/lib/astutils.cpp b/lib/astutils.cpp
index 1e75552ec4d..e5c31c01f72 100644
--- a/lib/astutils.cpp
+++ b/lib/astutils.cpp
@@ -409,22 +409,22 @@ bool isStlStringType(const Token* tok)
(Token::simpleMatch(tok, "std :: basic_string <") && !Token::simpleMatch(tok->linkAt(3), "> ::"));
}
-bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknown)
+bool isTemporary(const Token* tok, const Library* library, bool unknown)
{
if (!tok)
return false;
if (Token::simpleMatch(tok, "."))
- return (tok->originalName() != "->" && isTemporary(cpp, tok->astOperand1(), library)) ||
- isTemporary(cpp, tok->astOperand2(), library);
+ return (tok->originalName() != "->" && isTemporary(tok->astOperand1(), library)) ||
+ isTemporary(tok->astOperand2(), library);
if (Token::Match(tok, ",|::"))
- return isTemporary(cpp, tok->astOperand2(), library);
- if (tok->isCast() || (cpp && isCPPCast(tok)))
- return isTemporary(cpp, tok->astOperand2(), library);
+ return isTemporary(tok->astOperand2(), library);
+ if (tok->isCast() || (tok->isCpp() && isCPPCast(tok)))
+ return isTemporary(tok->astOperand2(), library);
if (Token::Match(tok, ".|[|++|--|%name%|%assign%"))
return false;
if (tok->isUnaryOp("*"))
return false;
- if (Token::Match(tok, "&|<<|>>") && isLikelyStream(cpp, tok->astOperand1()))
+ if (Token::Match(tok, "&|<<|>>") && isLikelyStream(tok->astOperand1()))
return false;
if (Token::simpleMatch(tok, "?")) {
const Token* branchTok = tok->astOperand2();
@@ -473,7 +473,7 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
return unknown;
if (Token::simpleMatch(tok, "{") && Token::simpleMatch(tok->astParent(), "return") && tok->astOperand1() &&
!tok->astOperand2())
- return isTemporary(cpp, tok->astOperand1(), library);
+ return isTemporary(tok->astOperand1(), library);
return true;
}
@@ -629,7 +629,7 @@ static std::vector getParentMembers(const Token* tok)
return result;
}
-const Token* getParentLifetime(bool cpp, const Token* tok, const Library* library)
+const Token* getParentLifetime(const Token* tok, const Library* library)
{
std::vector members = getParentMembers(tok);
if (members.size() < 2)
@@ -639,7 +639,7 @@ const Token* getParentLifetime(bool cpp, const Token* tok, const Library* librar
const Variable* var = tok2->variable();
if (var)
return var->isLocal() || var->isArgument();
- return isTemporary(cpp, tok2, library);
+ return isTemporary(tok2, library);
});
if (it == members.rend())
return tok;
@@ -1137,7 +1137,7 @@ bool isStructuredBindingVariable(const Variable* var)
/// This takes a token that refers to a variable and it will return the token
/// to the expression that the variable is assigned to. If its not valid to
/// make such substitution then it will return the original token.
-static const Token * followVariableExpression(const Token * tok, bool cpp, const Token * end = nullptr)
+static const Token * followVariableExpression(const Token * tok, const Token * end = nullptr)
{
if (!tok)
return tok;
@@ -1175,7 +1175,7 @@ static const Token * followVariableExpression(const Token * tok, bool cpp, const
const Token * lastTok = precedes(tok, end) ? end : tok;
// If this is in a loop then check if variables are modified in the entire scope
const Token * endToken = (isInLoopCondition(tok) || isInLoopCondition(varTok) || var->scope() != tok->scope()) ? var->scope()->bodyEnd : lastTok;
- if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, tok->varId(), false, nullptr, cpp)))
+ if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, tok->varId(), false, nullptr)))
return tok;
if (precedes(varTok, endToken) && isAliased(varTok, endToken, tok->varId()))
return tok;
@@ -1187,7 +1187,7 @@ static const Token * followVariableExpression(const Token * tok, bool cpp, const
return tok;
} else if (!precedes(startToken, endToken)) {
return tok;
- } else if (findExpressionChanged(varTok, startToken, endToken, nullptr, cpp)) {
+ } else if (findExpressionChanged(varTok, startToken, endToken, nullptr)) {
return tok;
}
return varTok;
@@ -1250,7 +1250,7 @@ SmallVector followAllReferences(const Token* tok,
return {};
errors.emplace_back(varDeclEndToken, "Assigned to reference.");
const Token *vartok = varDeclEndToken->astOperand2();
- if (vartok == tok || (!temporary && isTemporary(true, vartok, nullptr, true) &&
+ if (vartok == tok || (!temporary && isTemporary(vartok, nullptr, true) &&
(var->isConst() || var->isRValueReference()))) {
SmallVector refs_result;
refs_result.push_back({tok, std::move(errors)});
@@ -1527,13 +1527,14 @@ static bool astIsBoolLike(const Token* tok)
return astIsBool(tok) || isUsedAsBool(tok);
}
-bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
+bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
{
if (tok1 == nullptr && tok2 == nullptr)
return true;
if (tok1 == nullptr || tok2 == nullptr)
return false;
- if (cpp) {
+ // tokens needs to be from the same TokenList so no need check standard on both of them
+ if (tok1->isCpp()) {
if (tok1->str() == "." && tok1->astOperand1() && tok1->astOperand1()->str() == "this")
tok1 = tok1->astOperand2();
if (tok2->str() == "." && tok2->astOperand1() && tok2->astOperand1()->str() == "this")
@@ -1541,10 +1542,10 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
}
// Skip double not
if (Token::simpleMatch(tok1, "!") && Token::simpleMatch(tok1->astOperand1(), "!") && !Token::simpleMatch(tok1->astParent(), "=") && astIsBoolLike(tok2)) {
- return isSameExpression(cpp, macro, tok1->astOperand1()->astOperand1(), tok2, library, pure, followVar, errors);
+ return isSameExpression(macro, tok1->astOperand1()->astOperand1(), tok2, library, pure, followVar, errors);
}
if (Token::simpleMatch(tok2, "!") && Token::simpleMatch(tok2->astOperand1(), "!") && !Token::simpleMatch(tok2->astParent(), "=") && astIsBoolLike(tok1)) {
- return isSameExpression(cpp, macro, tok1, tok2->astOperand1()->astOperand1(), library, pure, followVar, errors);
+ return isSameExpression(macro, tok1, tok2->astOperand1()->astOperand1(), library, pure, followVar, errors);
}
const bool tok_str_eq = tok1->str() == tok2->str();
if (!tok_str_eq && isDifferentKnownValues(tok1, tok2))
@@ -1560,20 +1561,20 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
// Follow variable
if (followVar && !tok_str_eq && (followTok1->varId() || followTok2->varId() || followTok1->enumerator() || followTok2->enumerator())) {
- const Token * varTok1 = followVariableExpression(followTok1, cpp, followTok2);
+ const Token * varTok1 = followVariableExpression(followTok1, followTok2);
if ((varTok1->str() == followTok2->str()) || isSameConstantValue(macro, varTok1, followTok2)) {
followVariableExpressionError(followTok1, varTok1, errors);
- return isSameExpression(cpp, macro, varTok1, followTok2, library, true, followVar, errors);
+ return isSameExpression(macro, varTok1, followTok2, library, true, followVar, errors);
}
- const Token * varTok2 = followVariableExpression(followTok2, cpp, followTok1);
+ const Token * varTok2 = followVariableExpression(followTok2, followTok1);
if ((followTok1->str() == varTok2->str()) || isSameConstantValue(macro, followTok1, varTok2)) {
followVariableExpressionError(followTok2, varTok2, errors);
- return isSameExpression(cpp, macro, followTok1, varTok2, library, true, followVar, errors);
+ return isSameExpression(macro, followTok1, varTok2, library, true, followVar, errors);
}
if ((varTok1->str() == varTok2->str()) || isSameConstantValue(macro, varTok1, varTok2)) {
followVariableExpressionError(tok1, varTok1, errors);
followVariableExpressionError(tok2, varTok2, errors);
- return isSameExpression(cpp, macro, varTok1, varTok2, library, true, followVar, errors);
+ return isSameExpression(macro, varTok1, varTok2, library, true, followVar, errors);
}
}
// Follow references
@@ -1585,17 +1586,17 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
const Token *start = refTok1, *end = refTok2;
if (!precedes(start, end))
std::swap(start, end);
- if (findExpressionChanged(start, start, end, nullptr, cpp))
+ if (findExpressionChanged(start, start, end, nullptr))
return false;
}
- return isSameExpression(cpp, macro, refTok1, refTok2, library, pure, followVar, errors);
+ return isSameExpression(macro, refTok1, refTok2, library, pure, followVar, errors);
}
}
if (tok1->varId() != tok2->varId() || !tok_str_eq || tok1->originalName() != tok2->originalName()) {
if ((Token::Match(tok1,"<|>") && Token::Match(tok2,"<|>")) ||
(Token::Match(tok1,"<=|>=") && Token::Match(tok2,"<=|>="))) {
- return isSameExpression(cpp, macro, tok1->astOperand1(), tok2->astOperand2(), library, pure, followVar, errors) &&
- isSameExpression(cpp, macro, tok1->astOperand2(), tok2->astOperand1(), library, pure, followVar, errors);
+ return isSameExpression(macro, tok1->astOperand1(), tok2->astOperand2(), library, pure, followVar, errors) &&
+ isSameExpression(macro, tok1->astOperand2(), tok2->astOperand1(), library, pure, followVar, errors);
}
const Token* condTok = nullptr;
const Token* exprTok = nullptr;
@@ -1633,7 +1634,7 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
}
}
if (compare && astIsBoolLike(varTok1) && astIsBoolLike(varTok2))
- return isSameExpression(cpp, macro, varTok1, varTok2, library, pure, followVar, errors);
+ return isSameExpression(macro, varTok1, varTok2, library, pure, followVar, errors);
}
return false;
@@ -1714,15 +1715,15 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
return false;
}
bool noncommutativeEquals =
- isSameExpression(cpp, macro, tok1->astOperand1(), tok2->astOperand1(), library, pure, followVar, errors);
+ isSameExpression(macro, tok1->astOperand1(), tok2->astOperand1(), library, pure, followVar, errors);
noncommutativeEquals = noncommutativeEquals &&
- isSameExpression(cpp, macro, tok1->astOperand2(), tok2->astOperand2(), library, pure, followVar, errors);
+ isSameExpression(macro, tok1->astOperand2(), tok2->astOperand2(), library, pure, followVar, errors);
if (noncommutativeEquals)
return true;
// in c++, a+b might be different to b+a, depending on the type of a and b
- if (cpp && tok1->str() == "+" && tok1->isBinaryOp()) {
+ if (tok1->isCpp() && tok1->str() == "+" && tok1->isBinaryOp()) {
const ValueType* vt1 = tok1->astOperand1()->valueType();
const ValueType* vt2 = tok1->astOperand2()->valueType();
if (!(vt1 && (vt1->type >= ValueType::VOID || vt1->pointer) && vt2 && (vt2->type >= ValueType::VOID || vt2->pointer)))
@@ -1731,9 +1732,9 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
const bool commutative = tok1->isBinaryOp() && Token::Match(tok1, "%or%|%oror%|+|*|&|&&|^|==|!=");
bool commutativeEquals = commutative &&
- isSameExpression(cpp, macro, tok1->astOperand2(), tok2->astOperand1(), library, pure, followVar, errors);
+ isSameExpression(macro, tok1->astOperand2(), tok2->astOperand1(), library, pure, followVar, errors);
commutativeEquals = commutativeEquals &&
- isSameExpression(cpp, macro, tok1->astOperand1(), tok2->astOperand2(), library, pure, followVar, errors);
+ isSameExpression(macro, tok1->astOperand1(), tok2->astOperand2(), library, pure, followVar, errors);
return commutativeEquals;
@@ -1757,12 +1758,12 @@ static bool isZeroBoundCond(const Token * const cond)
return false;
}
-bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
+bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
{
if (!cond1 || !cond2)
return false;
- if (isSameExpression(cpp, true, cond1, cond2, library, pure, followVar, errors))
+ if (isSameExpression(true, cond1, cond2, library, pure, followVar, errors))
return false;
if (!isNot && cond1->str() == "&&" && cond2->str() == "&&") {
@@ -1772,8 +1773,8 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
for (const Token* tok2: {
cond2->astOperand1(), cond2->astOperand2()
}) {
- if (isSameExpression(cpp, true, tok1, tok2, library, pure, followVar, errors)) {
- if (isOppositeCond(isNot, cpp, tok1->astSibling(), tok2->astSibling(), library, pure, followVar, errors))
+ if (isSameExpression(true, tok1, tok2, library, pure, followVar, errors)) {
+ if (isOppositeCond(isNot, tok1->astSibling(), tok2->astSibling(), library, pure, followVar, errors))
return true;
}
}
@@ -1791,37 +1792,36 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
orCond = cond2;
otherCond = cond1;
}
- return isOppositeCond(isNot, cpp, orCond->astOperand1(), otherCond, library, pure, followVar, errors) &&
- isOppositeCond(isNot, cpp, orCond->astOperand2(), otherCond, library, pure, followVar, errors);
+ return isOppositeCond(isNot, orCond->astOperand1(), otherCond, library, pure, followVar, errors) &&
+ isOppositeCond(isNot, orCond->astOperand2(), otherCond, library, pure, followVar, errors);
}
if (cond1->str() == "!") {
if (cond2->str() == "!=") {
if (cond2->astOperand1() && cond2->astOperand1()->str() == "0")
- return isSameExpression(cpp, true, cond1->astOperand1(), cond2->astOperand2(), library, pure, followVar, errors);
+ return isSameExpression(true, cond1->astOperand1(), cond2->astOperand2(), library, pure, followVar, errors);
if (cond2->astOperand2() && cond2->astOperand2()->str() == "0")
- return isSameExpression(cpp, true, cond1->astOperand1(), cond2->astOperand1(), library, pure, followVar, errors);
+ return isSameExpression(true, cond1->astOperand1(), cond2->astOperand1(), library, pure, followVar, errors);
}
if (!isUsedAsBool(cond2))
return false;
- return isSameExpression(cpp, true, cond1->astOperand1(), cond2, library, pure, followVar, errors);
+ return isSameExpression(true, cond1->astOperand1(), cond2, library, pure, followVar, errors);
}
if (cond2->str() == "!")
- return isOppositeCond(isNot, cpp, cond2, cond1, library, pure, followVar, errors);
+ return isOppositeCond(isNot, cond2, cond1, library, pure, followVar, errors);
if (!isNot) {
if (cond1->str() == "==" && cond2->str() == "==") {
- if (isSameExpression(cpp, true, cond1->astOperand1(), cond2->astOperand1(), library, pure, followVar, errors))
+ if (isSameExpression(true, cond1->astOperand1(), cond2->astOperand1(), library, pure, followVar, errors))
return isDifferentKnownValues(cond1->astOperand2(), cond2->astOperand2());
- if (isSameExpression(cpp, true, cond1->astOperand2(), cond2->astOperand2(), library, pure, followVar, errors))
+ if (isSameExpression(true, cond1->astOperand2(), cond2->astOperand2(), library, pure, followVar, errors))
return isDifferentKnownValues(cond1->astOperand1(), cond2->astOperand1());
}
// TODO: Handle reverse conditions
if (Library::isContainerYield(cond1, Library::Container::Yield::EMPTY, "empty") &&
Library::isContainerYield(cond2->astOperand1(), Library::Container::Yield::SIZE, "size") &&
- isSameExpression(cpp,
- true,
+ isSameExpression(true,
cond1->astOperand1()->astOperand1(),
cond2->astOperand1()->astOperand1()->astOperand1(),
library,
@@ -1833,8 +1833,7 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
if (Library::isContainerYield(cond2, Library::Container::Yield::EMPTY, "empty") &&
Library::isContainerYield(cond1->astOperand1(), Library::Container::Yield::SIZE, "size") &&
- isSameExpression(cpp,
- true,
+ isSameExpression(true,
cond2->astOperand1()->astOperand1(),
cond1->astOperand1()->astOperand1()->astOperand1(),
library,
@@ -1853,11 +1852,11 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
// condition found .. get comparator
std::string comp2;
- if (isSameExpression(cpp, true, cond1->astOperand1(), cond2->astOperand1(), library, pure, followVar, errors) &&
- isSameExpression(cpp, true, cond1->astOperand2(), cond2->astOperand2(), library, pure, followVar, errors)) {
+ if (isSameExpression(true, cond1->astOperand1(), cond2->astOperand1(), library, pure, followVar, errors) &&
+ isSameExpression(true, cond1->astOperand2(), cond2->astOperand2(), library, pure, followVar, errors)) {
comp2 = cond2->str();
- } else if (isSameExpression(cpp, true, cond1->astOperand1(), cond2->astOperand2(), library, pure, followVar, errors) &&
- isSameExpression(cpp, true, cond1->astOperand2(), cond2->astOperand1(), library, pure, followVar, errors)) {
+ } else if (isSameExpression(true, cond1->astOperand1(), cond2->astOperand2(), library, pure, followVar, errors) &&
+ isSameExpression(true, cond1->astOperand2(), cond2->astOperand1(), library, pure, followVar, errors)) {
comp2 = cond2->str();
if (comp2[0] == '>')
comp2[0] = '<';
@@ -1893,7 +1892,7 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
if (!expr1 || !value1 || !expr2 || !value2) {
return false;
}
- if (!isSameExpression(cpp, true, expr1, expr2, library, pure, followVar, errors))
+ if (!isSameExpression(true, expr1, expr2, library, pure, followVar, errors))
return false;
const ValueFlow::Value &rhsValue1 = value1->values().front();
@@ -1921,16 +1920,16 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
)));
}
-bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
+bool isOppositeExpression(const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
{
if (!tok1 || !tok2)
return false;
- if (isOppositeCond(true, cpp, tok1, tok2, library, pure, followVar, errors))
+ if (isOppositeCond(true, tok1, tok2, library, pure, followVar, errors))
return true;
if (tok1->isUnaryOp("-") && !(tok2->astParent() && tok2->astParent()->tokType() == Token::eBitOp))
- return isSameExpression(cpp, true, tok1->astOperand1(), tok2, library, pure, followVar, errors);
+ return isSameExpression(true, tok1->astOperand1(), tok2, library, pure, followVar, errors);
if (tok2->isUnaryOp("-") && !(tok2->astParent() && tok2->astParent()->tokType() == Token::eBitOp))
- return isSameExpression(cpp, true, tok2->astOperand1(), tok1, library, pure, followVar, errors);
+ return isSameExpression(true, tok2->astOperand1(), tok1, library, pure, followVar, errors);
return false;
}
@@ -2023,7 +2022,7 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
return true;
}
-bool isConstExpression(const Token *tok, const Library& library, bool cpp)
+bool isConstExpression(const Token *tok, const Library& library)
{
if (!tok)
return true;
@@ -2037,17 +2036,19 @@ bool isConstExpression(const Token *tok, const Library& library, bool cpp)
return false;
if (tok->isAssignmentOp())
return false;
- if (isLikelyStreamRead(cpp, tok))
+ if (isLikelyStreamRead(tok))
return false;
// bailout when we see ({..})
if (tok->str() == "{")
return false;
- return isConstExpression(tok->astOperand1(), library, cpp) && isConstExpression(tok->astOperand2(), library, cpp);
+ return isConstExpression(tok->astOperand1(), library) && isConstExpression(tok->astOperand2(), library);
}
-bool isWithoutSideEffects(bool cpp, const Token* tok, bool checkArrayAccess, bool checkReference)
+bool isWithoutSideEffects(const Token* tok, bool checkArrayAccess, bool checkReference)
{
- if (!cpp)
+ if (!tok)
+ return true;
+ if (!tok->isCpp())
return true;
while (tok && tok->astOperand2() && tok->astOperand2()->str() != "(")
@@ -2520,7 +2521,7 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
return false;
}
-bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, bool cpp, int depth)
+bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, int depth)
{
if (!tok)
return false;
@@ -2577,7 +2578,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
const Variable * var = getLHSVariable(tok2->astParent());
if (var && var->isReference() && !var->isConst() &&
((var->nameToken() && var->nameToken()->next() == tok2->astParent()) || var->isPointer())) {
- if (!var->isLocal() || isVariableChanged(var, settings, cpp, depth - 1))
+ if (!var->isLocal() || isVariableChanged(var, settings, depth - 1))
return true;
}
}
@@ -2586,7 +2587,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
// Check addressof
if (tok2->astParent() && tok2->astParent()->isUnaryOp("&")) {
- if (isVariableChanged(tok2->astParent(), indirect + 1, settings, cpp, depth - 1))
+ if (isVariableChanged(tok2->astParent(), indirect + 1, settings, depth - 1))
return true;
} else {
// If its already const then it cant be modified
@@ -2594,10 +2595,10 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
return false;
}
- if (cpp && Token::Match(tok2->astParent(), ">>|&") && astIsRHS(tok2) && isLikelyStreamRead(cpp, tok2->astParent()))
+ if (tok2->isCpp() && Token::Match(tok2->astParent(), ">>|&") && astIsRHS(tok2) && isLikelyStreamRead(tok2->astParent()))
return true;
- if (isLikelyStream(cpp, tok2))
+ if (isLikelyStream(tok2))
return true;
// Member function call
@@ -2626,14 +2627,14 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
const Library::Container::Yield yield = c->getYield(ftok->str());
// If accessing element check if the element is changed
if (contains({Library::Container::Yield::ITEM, Library::Container::Yield::AT_INDEX}, yield))
- return isVariableChanged(ftok->next(), indirect, settings, cpp, depth - 1);
+ return isVariableChanged(ftok->next(), indirect, settings, depth - 1);
if (contains({Library::Container::Yield::BUFFER,
Library::Container::Yield::BUFFER_NT,
Library::Container::Yield::START_ITERATOR,
Library::Container::Yield::ITERATOR},
yield)) {
- return isVariableChanged(ftok->next(), indirect + 1, settings, cpp, depth - 1);
+ return isVariableChanged(ftok->next(), indirect + 1, settings, depth - 1);
}
if (contains({Library::Container::Yield::SIZE,
Library::Container::Yield::EMPTY,
@@ -2716,7 +2717,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
const Variable * loopVar = varTok->variable();
if (!loopVar)
return false;
- if (!loopVar->isConst() && loopVar->isReference() && isVariableChanged(loopVar, settings, cpp, depth - 1))
+ if (!loopVar->isConst() && loopVar->isReference() && isVariableChanged(loopVar, settings, depth - 1))
return true;
return false;
}
@@ -2738,14 +2739,14 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
return false;
}
-bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth)
+bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, int depth)
{
- return findVariableChanged(start, end, 0, exprid, globalvar, settings, cpp, depth) != nullptr;
+ return findVariableChanged(start, end, 0, exprid, globalvar, settings, depth) != nullptr;
}
-bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth)
+bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth)
{
- return findVariableChanged(start, end, indirect, exprid, globalvar, settings, cpp, depth) != nullptr;
+ return findVariableChanged(start, end, indirect, exprid, globalvar, settings, depth) != nullptr;
}
const Token* findExpression(const Token* start, const nonneg int exprid)
@@ -2788,7 +2789,6 @@ static bool isExpressionChangedAt(const F& getExprTok,
const nonneg int exprid,
bool globalvar,
const Settings* settings,
- bool cpp,
int depth)
{
if (depth < 0)
@@ -2809,14 +2809,14 @@ static bool isExpressionChangedAt(const F& getExprTok,
aliased = isAliasOf(tok, expr, &i);
if (!aliased)
return false;
- if (isVariableChanged(tok, indirect + i, settings, cpp, depth))
+ if (isVariableChanged(tok, indirect + i, settings, depth))
return true;
// TODO: Try to traverse the lambda function
if (Token::Match(tok, "%var% ("))
return true;
return false;
}
- return (isVariableChanged(tok, indirect, settings, cpp, depth));
+ return (isVariableChanged(tok, indirect, settings, depth));
}
bool isExpressionChangedAt(const Token* expr,
@@ -2824,15 +2824,14 @@ bool isExpressionChangedAt(const Token* expr,
int indirect,
bool globalvar,
const Settings* settings,
- bool cpp,
int depth)
{
return isExpressionChangedAt([&] {
return expr;
- }, tok, indirect, expr->exprId(), globalvar, settings, cpp, depth);
+ }, tok, indirect, expr->exprId(), globalvar, settings, depth);
}
-Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth)
+Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth)
{
if (!precedes(start, end))
return nullptr;
@@ -2842,18 +2841,18 @@ Token* findVariableChanged(Token *start, const Token *end, int indirect, const n
return findExpression(start, exprid);
});
for (Token *tok = start; tok != end; tok = tok->next()) {
- if (isExpressionChangedAt(getExprTok, tok, indirect, exprid, globalvar, settings, cpp, depth))
+ if (isExpressionChangedAt(getExprTok, tok, indirect, exprid, globalvar, settings, depth))
return tok;
}
return nullptr;
}
-const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth)
+const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth)
{
- return findVariableChanged(const_cast(start), end, indirect, exprid, globalvar, settings, cpp, depth);
+ return findVariableChanged(const_cast(start), end, indirect, exprid, globalvar, settings, depth);
}
-bool isVariableChanged(const Variable * var, const Settings *settings, bool cpp, int depth)
+bool isVariableChanged(const Variable * var, const Settings *settings, int depth)
{
if (!var)
return false;
@@ -2869,15 +2868,14 @@ bool isVariableChanged(const Variable * var, const Settings *settings, bool cpp,
if (next)
start = next;
}
- return findExpressionChanged(var->nameToken(), start->next(), var->scope()->bodyEnd, settings, cpp, depth);
+ return findExpressionChanged(var->nameToken(), start->next(), var->scope()->bodyEnd, settings, depth);
}
bool isVariablesChanged(const Token* start,
const Token* end,
int indirect,
const std::vector &vars,
- const Settings* settings,
- bool cpp)
+ const Settings* settings)
{
std::set varids;
std::transform(vars.cbegin(), vars.cend(), std::inserter(varids, varids.begin()), [](const Variable* var) {
@@ -2893,13 +2891,13 @@ bool isVariablesChanged(const Token* start,
return true;
continue;
}
- if (isVariableChanged(tok, indirect, settings, cpp))
+ if (isVariableChanged(tok, indirect, settings))
return true;
}
return false;
}
-bool isThisChanged(const Token* tok, int indirect, const Settings* settings, bool cpp)
+bool isThisChanged(const Token* tok, int indirect, const Settings* settings)
{
if ((Token::Match(tok->previous(), "%name% (") && !Token::simpleMatch(tok->astOperand1(), ".")) ||
Token::Match(tok->tokAt(-3), "this . %name% (")) {
@@ -2910,19 +2908,19 @@ bool isThisChanged(const Token* tok, int indirect, const Settings* settings, boo
return true;
}
}
- if (isVariableChanged(tok, indirect, settings, cpp))
+ if (isVariableChanged(tok, indirect, settings))
return true;
return false;
}
-const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings, bool cpp)
+const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings)
{
if (!precedes(start, end))
return nullptr;
for (const Token* tok = start; tok != end; tok = tok->next()) {
if (!exprDependsOnThis(tok))
continue;
- if (isThisChanged(tok, indirect, settings, cpp))
+ if (isThisChanged(tok, indirect, settings))
return tok;
}
return nullptr;
@@ -2933,7 +2931,6 @@ static const Token* findExpressionChangedImpl(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
- bool cpp,
int depth,
Find find)
{
@@ -2944,7 +2941,7 @@ static const Token* findExpressionChangedImpl(const Token* expr,
const Token* result = nullptr;
findAstNode(expr, [&](const Token* tok) {
if (exprDependsOnThis(tok)) {
- result = findThisChanged(start, end, /*indirect*/ 0, settings, cpp);
+ result = findThisChanged(start, end, /*indirect*/ 0, settings);
if (result)
return true;
}
@@ -2967,7 +2964,7 @@ static const Token* findExpressionChangedImpl(const Token* expr,
++indirect;
}
for (int i = 0; i <= indirect; ++i)
- if (isExpressionChangedAt(tok, tok2, i, global, settings, cpp, depth))
+ if (isExpressionChangedAt(tok, tok2, i, global, settings, depth))
return true;
return false;
});
@@ -3009,22 +3006,20 @@ const Token* findExpressionChanged(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
- bool cpp,
int depth)
{
- return findExpressionChangedImpl(expr, start, end, settings, cpp, depth, ExpressionChangedSimpleFind{});
+ return findExpressionChangedImpl(expr, start, end, settings, depth, ExpressionChangedSimpleFind{});
}
const Token* findExpressionChangedSkipDeadCode(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
- bool cpp,
const std::function(const Token* tok)>& evaluate,
int depth)
{
return findExpressionChangedImpl(
- expr, start, end, settings, cpp, depth, ExpressionChangedSkipDeadCode{&settings->library, evaluate});
+ expr, start, end, settings, depth, ExpressionChangedSkipDeadCode{&settings->library, evaluate});
}
const Token* getArgumentStart(const Token* ftok)
@@ -3183,12 +3178,12 @@ Token* findLambdaEndToken(Token* first)
return findLambdaEndTokenGeneric(first);
}
-bool isLikelyStream(bool cpp, const Token *stream)
+bool isLikelyStream(const Token *stream)
{
- if (!cpp)
+ if (!stream)
return false;
- if (!stream)
+ if (!stream->isCpp())
return false;
if (!Token::Match(stream->astParent(), "&|<<|>>") || !stream->astParent()->isBinaryOp())
@@ -3200,9 +3195,12 @@ bool isLikelyStream(bool cpp, const Token *stream)
return !astIsIntegral(stream, false);
}
-bool isLikelyStreamRead(bool cpp, const Token *op)
+bool isLikelyStreamRead(const Token *op)
{
- if (!cpp)
+ if (!op)
+ return false;
+
+ if (!op->isCpp())
return false;
if (!Token::Match(op, "&|>>") || !op->isBinaryOp())
@@ -3284,10 +3282,19 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
for (const Variable* arg : args) {
if (!arg)
continue;
- if (arg->isReference())
- return ExprUsage::PassedByReference;
- if (arg->isPointer() && indirect == 1)
- return ExprUsage::PassedByReference;
+ if (arg->isReference() || (arg->isPointer() && indirect == 1)) {
+ if (!ftok->function()->hasBody())
+ return ExprUsage::PassedByReference;
+ for (const Token* bodytok = ftok->function()->functionScope->bodyStart; bodytok != ftok->function()->functionScope->bodyEnd; bodytok = bodytok->next()) {
+ if (bodytok->variable() == arg) {
+ if (arg->isReference())
+ return ExprUsage::PassedByReference;
+ if (Token::Match(bodytok->astParent(), "%comp%|!"))
+ return ExprUsage::NotUsed;
+ return ExprUsage::PassedByReference;
+ }
+ }
+ }
}
if (!args.empty() && indirect == 0 && !addressOf)
return ExprUsage::Used;
@@ -3324,7 +3331,7 @@ bool isLeafDot(const Token* tok)
return isLeafDot(parent);
}
-ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp)
+ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings)
{
const Token* parent = tok->astParent();
if (indirect > 0 && parent) {
@@ -3339,12 +3346,12 @@ ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings,
if (parent->isCast())
return ExprUsage::NotUsed;
if (Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "?"))
- return getExprUsage(parent->astParent(), indirect, settings, cpp);
+ return getExprUsage(parent->astParent(), indirect, settings);
}
if (indirect == 0) {
if (Token::Match(parent, "%cop%|%assign%|++|--") && parent->str() != "=" &&
!parent->isUnaryOp("&") &&
- !(astIsRHS(tok) && isLikelyStreamRead(cpp, parent)))
+ !(astIsRHS(tok) && isLikelyStreamRead(parent)))
return ExprUsage::Used;
if (isLeafDot(tok)) {
const Token* op = parent->astParent();
@@ -3478,7 +3485,7 @@ bool isNullOperand(const Token *expr)
return Token::Match(castOp, "NULL|nullptr") || (MathLib::isInt(castOp->str()) && MathLib::isNullValue(castOp->str()));
}
-bool isGlobalData(const Token *expr, bool cpp)
+bool isGlobalData(const Token *expr)
{
// function call that returns reference => assume global data
if (expr && expr->str() == "(" && expr->valueType() && expr->valueType()->reference != Reference::None) {
@@ -3491,7 +3498,7 @@ bool isGlobalData(const Token *expr, bool cpp)
bool globalData = false;
bool var = false;
visitAstNodes(expr,
- [expr, cpp, &globalData, &var](const Token *tok) {
+ [expr, &globalData, &var](const Token *tok) {
if (tok->varId())
var = true;
if (tok->varId() && !tok->variable()) {
@@ -3549,7 +3556,7 @@ bool isGlobalData(const Token *expr, bool cpp)
}
}
// Unknown argument type => it might be some reference type..
- if (cpp && tok->str() == "." && tok->astOperand1() && tok->astOperand1()->variable() && !tok->astOperand1()->valueType()) {
+ if (tok->isCpp() && tok->str() == "." && tok->astOperand1() && tok->astOperand1()->variable() && !tok->astOperand1()->valueType()) {
globalData = true;
return ChildrenToVisit::none;
}
diff --git a/lib/astutils.h b/lib/astutils.h
index e39b61b33d6..10699f8de61 100644
--- a/lib/astutils.h
+++ b/lib/astutils.h
@@ -194,7 +194,7 @@ const Token * astIsVariableComparison(const Token *tok, const std::string &comp,
bool isVariableDecl(const Token* tok);
bool isStlStringType(const Token* tok);
-bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknown = false);
+bool isTemporary(const Token* tok, const Library* library, bool unknown = false);
const Token* previousBeforeAstLeftmostLeaf(const Token* tok);
Token* previousBeforeAstLeftmostLeaf(Token* tok);
@@ -208,7 +208,7 @@ const Token* astParentSkipParens(const Token* tok);
const Token* getParentMember(const Token * tok);
const Token* getParentLifetime(const Token* tok);
-const Token* getParentLifetime(bool cpp, const Token* tok, const Library* library);
+const Token* getParentLifetime(const Token* tok, const Library* library);
std::vector getParentValueTypes(const Token* tok,
const Settings* settings = nullptr,
@@ -261,7 +261,7 @@ SmallVector followAllReferences(const Token* tok,
int depth = 20);
const Token* followReferences(const Token* tok, ErrorPath* errors = nullptr);
-CPPCHECKLIB bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
+CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
bool isEqualKnownValue(const Token * const tok1, const Token * const tok2);
@@ -282,21 +282,20 @@ bool compareTokenFlags(const Token* tok1, const Token* tok2, bool macro);
/**
* Are two conditions opposite
* @param isNot do you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false
- * @param cpp c++ file
* @param cond1 condition1
* @param cond2 condition2
* @param library files data
* @param pure boolean
*/
-bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
+bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
-bool isOppositeExpression(bool cpp, const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
+bool isOppositeExpression(const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
bool isConstFunctionCall(const Token* ftok, const Library& library);
-bool isConstExpression(const Token *tok, const Library& library, bool cpp);
+bool isConstExpression(const Token *tok, const Library& library);
-bool isWithoutSideEffects(bool cpp, const Token* tok, bool checkArrayAccess = false, bool checkReference = true);
+bool isWithoutSideEffects(const Token* tok, bool checkArrayAccess = false, bool checkReference = true);
bool isUniqueExpression(const Token* tok);
@@ -341,38 +340,35 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int
CPPCHECKLIB bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Settings *settings, bool *inconclusive);
/** Is variable changed in block of code? */
-CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
-bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
+CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
+bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
-bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, bool cpp, int depth = 20);
+bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, int depth = 20);
-bool isVariableChanged(const Variable * var, const Settings *settings, bool cpp, int depth = 20);
+bool isVariableChanged(const Variable * var, const Settings *settings, int depth = 20);
bool isVariablesChanged(const Token* start,
const Token* end,
int indirect,
const std::vector &vars,
- const Settings* settings,
- bool cpp);
+ const Settings* settings);
-bool isThisChanged(const Token* tok, int indirect, const Settings* settings, bool cpp);
-const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings, bool cpp);
+bool isThisChanged(const Token* tok, int indirect, const Settings* settings);
+const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings);
-const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
-Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, bool cpp, int depth = 20);
+const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
+Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
CPPCHECKLIB const Token* findExpressionChanged(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
- bool cpp,
int depth = 20);
const Token* findExpressionChangedSkipDeadCode(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
- bool cpp,
const std::function(const Token* tok)>& evaluate,
int depth = 20);
@@ -381,7 +377,6 @@ bool isExpressionChangedAt(const Token* expr,
int indirect,
bool globalvar,
const Settings* settings,
- bool cpp,
int depth = 20);
/// If token is an alias if another variable
@@ -426,14 +421,14 @@ CPPCHECKLIB const Token *findLambdaStartToken(const Token *last);
CPPCHECKLIB const Token *findLambdaEndToken(const Token *first);
CPPCHECKLIB Token* findLambdaEndToken(Token* first);
-bool isLikelyStream(bool cpp, const Token *stream);
+bool isLikelyStream(const Token *stream);
/**
* do we see a likely write of rhs through overloaded operator
* s >> x;
* a & x;
*/
-bool isLikelyStreamRead(bool cpp, const Token *op);
+bool isLikelyStreamRead(const Token *op);
bool isCPPCast(const Token* tok);
@@ -443,7 +438,7 @@ bool isLeafDot(const Token* tok);
enum class ExprUsage { None, NotUsed, PassedByReference, Used, Inconclusive };
-ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp);
+ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings);
const Variable *getLHSVariable(const Token *tok);
@@ -458,7 +453,7 @@ bool isScopeBracket(const Token* tok);
CPPCHECKLIB bool isNullOperand(const Token *expr);
-bool isGlobalData(const Token *expr, bool cpp);
+bool isGlobalData(const Token *expr);
bool isUnevaluated(const Token *tok);
diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp
index 766cc185ade..7434fb3be3a 100644
--- a/lib/checkautovariables.cpp
+++ b/lib/checkautovariables.cpp
@@ -296,7 +296,7 @@ void CheckAutoVariables::autoVariables()
}
// Invalid pointer deallocation
else if ((Token::Match(tok, "%name% ( %var%|%str% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
- (mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
+ (tok->isCpp() && Token::Match(tok, "delete [| ]| (| %var%|%str% !!["))) {
tok = Token::findmatch(tok->next(), "%var%|%str%");
if (Token::simpleMatch(tok->astParent(), "."))
continue;
@@ -314,7 +314,7 @@ void CheckAutoVariables::autoVariables()
}
}
} else if ((Token::Match(tok, "%name% ( & %var% ) ;") && mSettings->library.getDeallocFuncInfo(tok)) ||
- (mTokenizer->isCPP() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
+ (tok->isCpp() && Token::Match(tok, "delete [| ]| (| & %var% !!["))) {
tok = Token::findmatch(tok->next(), "%var%");
if (isAutoVar(tok))
errorInvalidDeallocation(tok, nullptr);
@@ -463,9 +463,9 @@ static int getPointerDepth(const Token *tok)
return n;
}
-static bool isDeadTemporary(bool cpp, const Token* tok, const Token* expr, const Library* library)
+static bool isDeadTemporary(const Token* tok, const Token* expr, const Library* library)
{
- if (!isTemporary(cpp, tok, library))
+ if (!isTemporary(tok, library))
return false;
if (expr) {
if (!precedes(nextAfterAstRightmostLeaf(tok->astTop()), nextAfterAstRightmostLeaf(expr->astTop())))
@@ -495,7 +495,7 @@ static bool isEscapedReference(const Variable* var)
if (!Token::simpleMatch(varDeclEndToken, "="))
return false;
const Token* vartok = varDeclEndToken->astOperand2();
- return !isTemporary(true, vartok, nullptr, false);
+ return !isTemporary(vartok, nullptr, false);
}
static bool isDanglingSubFunction(const Token* tokvalue, const Token* tok)
@@ -562,7 +562,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
errorReturnReference(tok, lt.errorPath, lt.inconclusive);
break;
}
- if (isDeadTemporary(mTokenizer->isCPP(), lt.token, nullptr, &mSettings->library)) {
+ if (isDeadTemporary(lt.token, nullptr, &mSettings->library)) {
errorReturnTempReference(tok, lt.errorPath, lt.inconclusive);
break;
}
@@ -584,7 +584,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
if (!printInconclusive && lt.inconclusive)
continue;
const Token * tokvalue = lt.token;
- if (isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
+ if (isDeadTemporary(tokvalue, tok, &mSettings->library)) {
errorDanglingTempReference(tok, lt.errorPath, lt.inconclusive);
break;
}
@@ -598,7 +598,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
continue;
if (!printInconclusive && val.isInconclusive())
continue;
- const Token* parent = getParentLifetime(mTokenizer->isCPP(), val.tokvalue, &mSettings->library);
+ const Token* parent = getParentLifetime(val.tokvalue, &mSettings->library);
if (!exprs.insert(parent).second)
continue;
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, escape || isAssignedToNonLocal(tok))) {
@@ -614,7 +614,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
continue;
if ((tokvalue->variable() && !isEscapedReference(tokvalue->variable()) &&
isInScope(tokvalue->variable()->nameToken(), scope)) ||
- isDeadTemporary(mTokenizer->isCPP(), tokvalue, nullptr, &mSettings->library)) {
+ isDeadTemporary(tokvalue, nullptr, &mSettings->library)) {
errorReturnDanglingLifetime(tok, &val);
break;
}
@@ -622,7 +622,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
errorInvalidLifetime(tok, &val);
break;
} else if (!tokvalue->variable() &&
- isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
+ isDeadTemporary(tokvalue, tok, &mSettings->library)) {
if (!diag(tokvalue))
errorDanglingTemporaryLifetime(tok, &val, tokvalue);
break;
@@ -650,8 +650,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
tok->scope()->bodyEnd,
var->declarationId(),
var->isGlobal(),
- mSettings,
- mTokenizer->isCPP())) {
+ mSettings)) {
errorDanglngLifetime(tok2, &val);
break;
}
diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp
index 16e1471db07..609fc4c701a 100644
--- a/lib/checkbool.cpp
+++ b/lib/checkbool.cpp
@@ -122,7 +122,7 @@ void CheckBool::checkBitwiseOnBoolean()
if (tok->str() == "|" && !isConvertedToBool(tok) && !(isBoolOp1 && isBoolOp2))
continue;
// first operand will always be evaluated
- if (!isConstExpression(tok->astOperand2(), mSettings->library, mTokenizer->isCPP()))
+ if (!isConstExpression(tok->astOperand2(), mSettings->library))
continue;
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
continue;
diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp
index 49cb2036ff3..5c5cc5e0c81 100644
--- a/lib/checkbufferoverrun.cpp
+++ b/lib/checkbufferoverrun.cpp
@@ -327,7 +327,7 @@ void CheckBufferOverrun::arrayIndex()
const Token* changeTok = var->scope()->bodyStart;
bool isChanged = false;
while ((changeTok = findVariableChanged(changeTok->next(), var->scope()->bodyEnd, /*indirect*/ 0, var->declarationId(),
- /*globalvar*/ false, mSettings, mTokenizer->isCPP()))) {
+ /*globalvar*/ false, mSettings))) {
if (!Token::simpleMatch(changeTok->astParent(), "[")) {
isChanged = true;
break;
@@ -793,7 +793,7 @@ void CheckBufferOverrun::stringNotZeroTerminated()
const Token *rhs = tok2->next()->astOperand2();
if (!rhs || !rhs->hasKnownIntValue() || rhs->getKnownIntValue() != 0)
continue;
- if (isSameExpression(mTokenizer->isCPP(), false, args[0], tok2->link()->astOperand1(), mSettings->library, false, false))
+ if (isSameExpression(false, args[0], tok2->link()->astOperand1(), mSettings->library, false, false))
isZeroTerminated = true;
}
if (isZeroTerminated)
@@ -1090,7 +1090,7 @@ void CheckBufferOverrun::objectIndex()
if (var->valueType()->pointer > obj->valueType()->pointer)
continue;
}
- if (obj->valueType() && var->valueType() && (obj->isCast() || (mTokenizer->isCPP() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type
+ if (obj->valueType() && var->valueType() && (obj->isCast() || (obj->isCpp() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type
const auto varSize = var->valueType()->typeSize(mSettings->platform);
if (varSize == 0)
continue;
diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp
index 7e4d4adc443..627f15574b7 100644
--- a/lib/checkclass.cpp
+++ b/lib/checkclass.cpp
@@ -503,7 +503,7 @@ void CheckClass::copyconstructors()
}
}
for (tok = func.functionScope->bodyStart; tok != func.functionScope->bodyEnd; tok = tok->next()) {
- if ((mTokenizer->isCPP() && Token::Match(tok, "%var% = new")) ||
+ if ((tok->isCpp() && Token::Match(tok, "%var% = new")) ||
(Token::Match(tok, "%var% = %name% (") && (mSettings->library.getAllocFuncInfo(tok->tokAt(2)) || mSettings->library.getReallocFuncInfo(tok->tokAt(2))))) {
allocatedVars.erase(tok->varId());
} else if (Token::Match(tok, "%var% = %name% . %name% ;") && allocatedVars.find(tok->varId()) != allocatedVars.end()) {
@@ -817,7 +817,7 @@ void CheckClass::initializeVarList(const Function &func, std::list>|& %name%") && isLikelyStreamRead(true, ftok)) {
+ if (Token::Match(ftok, ">>|& %name%") && isLikelyStreamRead(ftok)) {
assignVar(usage, ftok->next()->varId());
}
@@ -1771,7 +1771,7 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope, const T
if (!end)
end = func->functionScope->bodyEnd;
for (const Token *tok = start; tok && (tok != end); tok = tok->next()) {
- if (((mTokenizer->isCPP() && Token::Match(tok, "%var% = new")) ||
+ if (((tok->isCpp() && Token::Match(tok, "%var% = new")) ||
(Token::Match(tok, "%var% = %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) &&
isMemberVar(scope, tok))
return true;
@@ -1780,9 +1780,9 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope, const T
const Token *var;
if (Token::Match(tok, "%name% ( %var%") && mSettings->library.getDeallocFuncInfo(tok))
var = tok->tokAt(2);
- else if (mTokenizer->isCPP() && Token::Match(tok, "delete [ ] %var%"))
+ else if (tok->isCpp() && Token::Match(tok, "delete [ ] %var%"))
var = tok->tokAt(3);
- else if (mTokenizer->isCPP() && Token::Match(tok, "delete %var%"))
+ else if (tok->isCpp() && Token::Match(tok, "delete %var%"))
var = tok->next();
else
continue;
@@ -2552,7 +2552,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
// Streaming
else if (end->strAt(1) == "<<" && tok1->strAt(-1) != "<<")
return false;
- else if (isLikelyStreamRead(true, tok1->previous()))
+ else if (isLikelyStreamRead(tok1->previous()))
return false;
// ++/--
@@ -2581,7 +2581,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
}
// streaming: >> *this
- else if (Token::simpleMatch(tok1, ">> * this") && isLikelyStreamRead(true, tok1)) {
+ else if (Token::simpleMatch(tok1, ">> * this") && isLikelyStreamRead(tok1)) {
return false;
}
diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp
index b39b69cbd40..f5e250a0cd8 100644
--- a/lib/checkcondition.cpp
+++ b/lib/checkcondition.cpp
@@ -200,7 +200,7 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok,
// is variable changed in loop?
const Token *bodyStart = tok2->linkAt(1)->next();
const Token *bodyEnd = bodyStart ? bodyStart->link() : nullptr;
- if (!bodyEnd || bodyEnd->str() != "}" || isVariableChanged(bodyStart, bodyEnd, varid, !islocal, mSettings, mTokenizer->isCPP()))
+ if (!bodyEnd || bodyEnd->str() != "}" || isVariableChanged(bodyStart, bodyEnd, varid, !islocal, mSettings))
continue;
}
@@ -435,7 +435,7 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *
return false;
// same expressions
- if (isSameExpression(mTokenizer->isCPP(), true, cond1, cond2, mSettings->library, pure, false))
+ if (isSameExpression(true, cond1, cond2, mSettings->library, pure, false))
return true;
// bitwise overlap for example 'x&7' and 'x==1'
@@ -458,7 +458,7 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *
if (!num2->isNumber() || MathLib::isNegative(num2->str()))
return false;
- if (!isSameExpression(mTokenizer->isCPP(), true, expr1, expr2, mSettings->library, pure, false))
+ if (!isSameExpression(true, expr1, expr2, mSettings->library, pure, false))
return false;
const MathLib::bigint value1 = MathLib::toBigNumber(num1->str());
@@ -503,8 +503,8 @@ void CheckCondition::duplicateCondition()
continue;
ErrorPath errorPath;
- if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings, mTokenizer->isCPP()) &&
- isSameExpression(mTokenizer->isCPP(), true, cond1, cond2, mSettings->library, true, true, &errorPath))
+ if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings) &&
+ isSameExpression(true, cond1, cond2, mSettings->library, true, true, &errorPath))
duplicateConditionError(cond1, cond2, std::move(errorPath));
}
}
@@ -553,11 +553,11 @@ void CheckCondition::multiCondition()
if (tok2->astOperand2()) {
ErrorPath errorPath;
if (isOverlappingCond(cond1, tok2->astOperand2(), true) &&
- !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings, mTokenizer->isCPP()))
+ !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings))
overlappingElseIfConditionError(tok2->astOperand2(), cond1->linenr());
else if (isOppositeCond(
- true, mTokenizer->isCPP(), cond1, tok2->astOperand2(), mSettings->library, true, true, &errorPath) &&
- !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings, mTokenizer->isCPP()))
+ true, cond1, tok2->astOperand2(), mSettings->library, true, true, &errorPath) &&
+ !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings))
oppositeElseIfConditionError(cond1, tok2->astOperand2(), std::move(errorPath));
}
}
@@ -665,7 +665,7 @@ void CheckCondition::multiCondition2()
}
} else if (!nonlocal && cond->isName()) {
// varid is 0. this is possibly a nonlocal variable..
- nonlocal = Token::Match(cond->astParent(), "%cop%|(|[") || Token::Match(cond, "%name% .") || (mTokenizer->isCPP() && cond->str() == "this");
+ nonlocal = Token::Match(cond->astParent(), "%cop%|(|[") || Token::Match(cond, "%name% .") || (cond->isCpp() && cond->str() == "this");
} else {
return ChildrenToVisit::op1_and_op2;
}
@@ -703,13 +703,13 @@ void CheckCondition::multiCondition2()
const Token * const endToken = tok->scope()->bodyEnd;
for (; tok && tok != endToken; tok = tok->next()) {
- if (isExpressionChangedAt(cond1, tok, 0, false, mSettings, mTokenizer->isCPP()))
+ if (isExpressionChangedAt(cond1, tok, 0, false, mSettings))
break;
if (Token::Match(tok, "if|return")) {
const Token * condStartToken = tok->str() == "if" ? tok->next() : tok;
const Token * condEndToken = tok->str() == "if" ? condStartToken->link() : Token::findsimplematch(condStartToken, ";");
// Does condition modify tracked variables?
- if (findExpressionChanged(cond1, condStartToken, condEndToken, mSettings, mTokenizer->isCPP()))
+ if (findExpressionChanged(cond1, condStartToken, condEndToken, mSettings))
break;
// Condition..
@@ -723,14 +723,14 @@ void CheckCondition::multiCondition2()
if (!firstCondition)
return ChildrenToVisit::none;
if (firstCondition->str() == "&&") {
- if (!isOppositeCond(false, mTokenizer->isCPP(), firstCondition, cond2, mSettings->library, true, true))
+ if (!isOppositeCond(false, firstCondition, cond2, mSettings->library, true, true))
return ChildrenToVisit::op1_and_op2;
}
if (!firstCondition->hasKnownIntValue()) {
- if (!isReturnVar && isOppositeCond(false, mTokenizer->isCPP(), firstCondition, cond2, mSettings->library, true, true, &errorPath)) {
+ if (!isReturnVar && isOppositeCond(false, firstCondition, cond2, mSettings->library, true, true, &errorPath)) {
if (!isAliased(vars))
oppositeInnerConditionError(firstCondition, cond2, errorPath);
- } else if (!isReturnVar && isSameExpression(mTokenizer->isCPP(), true, firstCondition, cond2, mSettings->library, true, true, &errorPath)) {
+ } else if (!isReturnVar && isSameExpression(true, firstCondition, cond2, mSettings->library, true, true, &errorPath)) {
identicalInnerConditionError(firstCondition, cond2, errorPath);
}
}
@@ -742,7 +742,7 @@ void CheckCondition::multiCondition2()
return ChildrenToVisit::op1_and_op2;
if ((!cond1->hasKnownIntValue() || !secondCondition->hasKnownIntValue()) &&
- isSameExpression(mTokenizer->isCPP(), true, cond1, secondCondition, mSettings->library, true, true, &errorPath)) {
+ isSameExpression(true, cond1, secondCondition, mSettings->library, true, true, &errorPath)) {
if (!isAliased(vars) && !mTokenizer->hasIfdef(cond1, secondCondition)) {
identicalConditionAfterEarlyExitError(cond1, secondCondition, errorPath);
return ChildrenToVisit::done;
@@ -753,7 +753,7 @@ void CheckCondition::multiCondition2()
}
}
if (Token::Match(tok, "%name% (") &&
- isVariablesChanged(tok, tok->linkAt(1), 0, varsInCond, mSettings, mTokenizer->isCPP())) {
+ isVariablesChanged(tok, tok->linkAt(1), 0, varsInCond, mSettings)) {
break;
}
if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok, mSettings->library)) // non const function call -> bailout if there are nonlocal variables
@@ -782,7 +782,7 @@ void CheckCondition::multiCondition2()
break;
}
const bool changed = std::any_of(vars.cbegin(), vars.cend(), [&](int varid) {
- return isVariableChanged(tok1, tok2, varid, nonlocal, mSettings, mTokenizer->isCPP());
+ return isVariableChanged(tok1, tok2, varid, nonlocal, mSettings);
});
if (changed)
break;
@@ -799,9 +799,9 @@ void CheckCondition::multiCondition2()
if (Token::Match(parent->astParent(), "%assign%|++|--"))
break;
}
- if (mTokenizer->isCPP() && Token::Match(tok, "%name% <<") && (!tok->valueType() || !tok->valueType()->isIntegral()))
+ if (tok->isCpp() && Token::Match(tok, "%name% <<") && (!tok->valueType() || !tok->valueType()->isIntegral()))
break;
- if (isLikelyStreamRead(mTokenizer->isCPP(), tok->next()) || isLikelyStreamRead(mTokenizer->isCPP(), tok->previous()))
+ if (isLikelyStreamRead(tok->next()) || isLikelyStreamRead(tok->previous()))
break;
if (Token::Match(tok, "%name% [")) {
const Token *tok2 = tok->linkAt(1);
@@ -1145,7 +1145,7 @@ void CheckCondition::checkIncorrectLogicOperator()
((tok->str() == "||" && tok->astOperand2()->str() == "&&") ||
(tok->str() == "&&" && tok->astOperand2()->str() == "||"))) {
const Token* tok2 = tok->astOperand2()->astOperand1();
- if (isOppositeCond(true, mTokenizer->isCPP(), tok->astOperand1(), tok2, mSettings->library, true, false)) {
+ if (isOppositeCond(true, tok->astOperand1(), tok2, mSettings->library, true, false)) {
std::string expr1(tok->astOperand1()->expressionString());
std::string expr2(tok->astOperand2()->astOperand1()->expressionString());
std::string expr3(tok->astOperand2()->astOperand2()->expressionString());
@@ -1177,7 +1177,7 @@ void CheckCondition::checkIncorrectLogicOperator()
redundantConditionError(tok, msg, false);
continue;
}
- if (isSameExpression(mTokenizer->isCPP(), false, tok->astOperand1(), tok2, mSettings->library, true, true)) {
+ if (isSameExpression(false, tok->astOperand1(), tok2, mSettings->library, true, true)) {
std::string expr1(tok->astOperand1()->expressionString());
std::string expr2(tok->astOperand2()->astOperand1()->expressionString());
std::string expr3(tok->astOperand2()->astOperand2()->expressionString());
@@ -1242,7 +1242,7 @@ void CheckCondition::checkIncorrectLogicOperator()
// Opposite comparisons around || or && => always true or always false
const bool isLogicalOr(tok->str() == "||");
- if (!isfloat && isOppositeCond(isLogicalOr, mTokenizer->isCPP(), tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true, &errorPath)) {
+ if (!isfloat && isOppositeCond(isLogicalOr, tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true, &errorPath)) {
if (!isIfConstexpr(tok)) {
const bool alwaysTrue(isLogicalOr);
incorrectLogicOperatorError(tok, conditionString(tok), alwaysTrue, inconclusive, errorPath);
@@ -1253,9 +1253,9 @@ void CheckCondition::checkIncorrectLogicOperator()
if (!parseable)
continue;
- if (isSameExpression(mTokenizer->isCPP(), true, comp1, comp2, mSettings->library, true, true))
+ if (isSameExpression(true, comp1, comp2, mSettings->library, true, true))
continue; // same expressions => only report that there are same expressions
- if (!isSameExpression(mTokenizer->isCPP(), true, expr1, expr2, mSettings->library, true, true))
+ if (!isSameExpression(true, expr1, expr2, mSettings->library, true, true))
continue;
@@ -1555,9 +1555,8 @@ void CheckCondition::alwaysTrueFalse()
continue;
if (Token::Match(tok->astOperand1(), "%name% (") && Token::simpleMatch(tok->astParent(), "return"))
continue;
- if (tok->isComparisonOp() && isWithoutSideEffects(mTokenizer->isCPP(), tok->astOperand1()) &&
- isSameExpression(mTokenizer->isCPP(),
- true,
+ if (tok->isComparisonOp() && isWithoutSideEffects(tok->astOperand1()) &&
+ isSameExpression(true,
tok->astOperand1(),
tok->astOperand2(),
mSettings->library,
@@ -1685,8 +1684,7 @@ void CheckCondition::checkInvalidTestForOverflow()
if (expr->hasKnownIntValue())
continue;
- if (!isSameExpression(mTokenizer->isCPP(),
- true,
+ if (!isSameExpression(true,
expr,
lhs->astSibling(),
mSettings->library,
@@ -1836,10 +1834,10 @@ void CheckCondition::checkDuplicateConditionalAssign()
isRedundant = (isNegation && val == 0) || (!isNegation && val == 1);
} else { // comparison
if (!isSameExpression(
- mTokenizer->isCPP(), true, condTok->astOperand1(), assignTok->astOperand1(), mSettings->library, true, true))
+ true, condTok->astOperand1(), assignTok->astOperand1(), mSettings->library, true, true))
continue;
if (!isSameExpression(
- mTokenizer->isCPP(), true, condTok->astOperand2(), assignTok->astOperand2(), mSettings->library, true, true))
+ true, condTok->astOperand2(), assignTok->astOperand2(), mSettings->library, true, true))
continue;
}
duplicateConditionalAssignError(condTok, assignTok, isRedundant);
diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp
index 7c2a58eb0d4..bfc370faefe 100644
--- a/lib/checkfunctions.cpp
+++ b/lib/checkfunctions.cpp
@@ -88,7 +88,7 @@ void CheckFunctions::checkProhibitedFunctions()
const Library::WarnInfo* wi = mSettings->library.getWarnInfo(tok);
if (wi) {
- if (mSettings->severity.isEnabled(wi->severity) && mSettings->standards.c >= wi->standards.c && mSettings->standards.cpp >= wi->standards.cpp) {
+ if (mSettings->severity.isEnabled(wi->severity) && ((tok->isC() && mSettings->standards.c >= wi->standards.c) || (tok->isCpp() && mSettings->standards.cpp >= wi->standards.cpp))) {
const std::string daca = mSettings->daca ? "prohibited" : "";
reportError(tok, wi->severity, daca + tok->str() + "Called", wi->message, CWE477, Certainty::normal);
}
@@ -148,7 +148,7 @@ void CheckFunctions::invalidFunctionUsage()
// Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ?
if (variable && variable->isLocal()
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)
- && !isVariablesChanged(variable->declEndToken(), functionToken, 0 /*indirect*/, { variable }, mSettings, mTokenizer->isCPP())) {
+ && !isVariablesChanged(variable->declEndToken(), functionToken, 0 /*indirect*/, { variable }, mSettings)) {
const Token* varTok = variable->declEndToken();
auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
if (varTok && Token::simpleMatch(varTok->astOperand1(), "["))
@@ -423,7 +423,7 @@ void CheckFunctions::missingReturnError(const Token* tok)
//---------------------------------------------------------------------------
void CheckFunctions::checkMathFunctions()
{
- const bool styleC99 = mSettings->severity.isEnabled(Severity::style) && mSettings->standards.c != Standards::C89 && mSettings->standards.cpp != Standards::CPP03;
+ const bool styleC99 = mSettings->severity.isEnabled(Severity::style) && ((mTokenizer->isC() && mSettings->standards.c != Standards::C89) || (mTokenizer->isCPP() && mSettings->standards.cpp != Standards::CPP03));
const bool printWarnings = mSettings->severity.isEnabled(Severity::warning);
if (!styleC99 && !printWarnings && !mSettings->isPremiumEnabled("wrongmathcall"))
@@ -756,10 +756,10 @@ void CheckFunctions::useStandardLibrary()
const auto& secondOp = condToken->str();
const bool isLess = "<" == secondOp &&
- isConstExpression(condToken->astOperand2(), mSettings->library, mTokenizer->isCPP()) &&
+ isConstExpression(condToken->astOperand2(), mSettings->library) &&
condToken->astOperand1()->varId() == idxVarId;
const bool isMore = ">" == secondOp &&
- isConstExpression(condToken->astOperand1(), mSettings->library, mTokenizer->isCPP()) &&
+ isConstExpression(condToken->astOperand1(), mSettings->library) &&
condToken->astOperand2()->varId() == idxVarId;
if (!(isLess || isMore))
@@ -776,7 +776,7 @@ void CheckFunctions::useStandardLibrary()
// technically using void* here is not correct but some compilers could allow it
const Token *tok = scope.bodyStart;
- const std::string memcpyName = mTokenizer->isCPP() ? "std::memcpy" : "memcpy";
+ const std::string memcpyName = tok->isCpp() ? "std::memcpy" : "memcpy";
// (reinterpret_cast(dest))[i] = (reinterpret_cast(src))[i];
if (Token::Match(tok, "{ (| reinterpret_cast < uint8_t|int8_t|char|void * > ( %var% ) )| [ %varid% ] = "
"(| reinterpret_cast < const| uint8_t|int8_t|char|void * > ( %var% ) )| [ %varid% ] ; }", idxVarId)) {
@@ -792,7 +792,7 @@ void CheckFunctions::useStandardLibrary()
}
- const static std::string memsetName = mTokenizer->isCPP() ? "std::memset" : "memset";
+ const static std::string memsetName = tok->isCpp() ? "std::memset" : "memset";
// ((char*)dst)[i] = 0;
if (Token::Match(tok, "{ ( ( uint8_t|int8_t|char|void * ) (| %var% ) )| [ %varid% ] = %char%|%num% ; }", idxVarId)) {
useStandardLibraryError(tok->next(), memsetName);
diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp
index 7ac325ac567..aee4e88ba6f 100644
--- a/lib/checkleakautovar.cpp
+++ b/lib/checkleakautovar.cpp
@@ -254,7 +254,7 @@ static bool isPointerReleased(const Token *startToken, const Token *endToken, no
return false;
}
-static bool isLocalVarNoAutoDealloc(const Token *varTok, const bool isCpp)
+static bool isLocalVarNoAutoDealloc(const Token *varTok)
{
// not a local variable nor argument?
const Variable *var = varTok->variable();
@@ -268,7 +268,7 @@ static bool isLocalVarNoAutoDealloc(const Token *varTok, const bool isCpp)
return false;
// non-pod variable
- if (isCpp) {
+ if (varTok->isCpp()) {
// Possibly automatically deallocated memory
if (isAutoDealloc(var) && Token::Match(varTok, "%var% [=({] new"))
return false;
@@ -432,7 +432,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
leakIfAllocated(varTok, varInfo);
varInfo.erase(varTok->varId());
- if (!isLocalVarNoAutoDealloc(varTok, mTokenizer->isCPP()))
+ if (!isLocalVarNoAutoDealloc(varTok))
continue;
// allocation?
@@ -447,7 +447,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
}
changeAllocStatusIfRealloc(alloctype, fTok, varTok);
- } else if (mTokenizer->isCPP() && Token::Match(varTok->tokAt(2), "new !!(")) {
+ } else if (varTok->isCpp() && Token::Match(varTok->tokAt(2), "new !!(")) {
const Token* tok2 = varTok->tokAt(2)->astOperand1();
const bool arrayNew = (tok2 && (tok2->str() == "[" || (Token::Match(tok2, "(|{") && tok2->astOperand1() && tok2->astOperand1()->str() == "[")));
VarInfo::AllocInfo& varAlloc = alloctype[varTok->varId()];
@@ -481,7 +481,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
if (!openingPar)
checkTokenInsideExpression(innerTok, varInfo);
- if (!isLocalVarNoAutoDealloc(innerTok, mTokenizer->isCPP()))
+ if (!isLocalVarNoAutoDealloc(innerTok))
continue;
// Check assignments in the if-statement. Skip multiple assignments since we don't track those
@@ -505,7 +505,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
alloctype.erase(innerTok->varId());
}
changeAllocStatusIfRealloc(alloctype, fTok, varTok);
- } else if (mTokenizer->isCPP() && Token::Match(innerTok->tokAt(2), "new !!(")) {
+ } else if (innerTok->isCpp() && Token::Match(innerTok->tokAt(2), "new !!(")) {
const Token* tok2 = innerTok->tokAt(2)->astOperand1();
const bool arrayNew = (tok2 && (tok2->str() == "[" || (tok2->str() == "(" && tok2->astOperand1() && tok2->astOperand1()->str() == "[")));
VarInfo::AllocInfo& varAlloc = alloctype[innerTok->varId()];
@@ -656,7 +656,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
}
// throw
- else if (mTokenizer->isCPP() && tok->str() == "throw") {
+ else if (tok->isCpp() && tok->str() == "throw") {
bool tryFound = false;
const Scope* scope = tok->scope();
while (scope && scope->isExecutable()) {
@@ -671,7 +671,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
}
// delete
- else if (mTokenizer->isCPP() && tok->str() == "delete") {
+ else if (tok->isCpp() && tok->str() == "delete") {
const Token * delTok = tok;
if (Token::simpleMatch(delTok->astOperand1(), "."))
continue;
@@ -962,7 +962,7 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
int argNr = 1;
for (const Token *funcArg = tokFirstArg; funcArg; funcArg = funcArg->nextArgument()) {
const Token* arg = funcArg;
- if (mTokenizer->isCPP()) {
+ if (arg->isCpp()) {
int tokAdvance = 0;
if (arg->str() == "new")
tokAdvance = 1;
@@ -985,12 +985,14 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
while (Token::Match(arg, "%name% .|:: %name%"))
arg = arg->tokAt(2);
- if (Token::Match(arg, "%var% [-,)] !!.") || Token::Match(arg, "& %var% !!.")) {
+ if ((Token::Match(arg, "%var% [-,)] !!.") && !(arg->variable() && arg->variable()->isArray())) ||
+ (Token::Match(arg, "& %var% !!.") && !(arg->next()->variable() && arg->next()->variable()->isArray()))) {
// goto variable
- if (arg->str() == "&")
+ const bool isAddressOf = arg->str() == "&";
+ if (isAddressOf)
arg = arg->next();
- const bool isnull = arg->hasKnownIntValue() && arg->values().front().intvalue == 0;
+ const bool isnull = !isAddressOf && (arg->hasKnownIntValue() && arg->values().front().intvalue == 0);
// Is variable allocated?
if (!isnull && (!af || af->arg == argNr)) {
@@ -1000,7 +1002,9 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
if (mSettings->library.getDeallocFuncInfo(tokName)) {
changeAllocStatus(varInfo, dealloc.type == 0 ? allocation : dealloc, tokName, arg);
}
- if (allocFunc->arg == argNr && !(arg->variable() && arg->variable()->isArgument() && arg->valueType() && arg->valueType()->pointer > 1)) {
+ if (allocFunc->arg == argNr &&
+ !(arg->variable() && arg->variable()->isArgument() && arg->valueType() && arg->valueType()->pointer > 1) &&
+ (isAddressOf || (arg->valueType() && arg->valueType()->pointer == 2))) {
leakIfAllocated(arg, varInfo);
VarInfo::AllocInfo& varAlloc = varInfo.alloctype[arg->varId()];
varAlloc.type = allocFunc->groupId;
diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp
index 28542238444..bc8cdd9e50a 100644
--- a/lib/checkmemoryleak.cpp
+++ b/lib/checkmemoryleak.cpp
@@ -76,7 +76,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
if (reallocType != No)
return reallocType;
- if (mTokenizer_->isCPP() && tok2->str() == "new") {
+ if (tok2->isCpp() && tok2->str() == "new") {
if (tok2->strAt(1) == "(" && !Token::Match(tok2->next(),"( std| ::| nothrow )"))
return No;
if (tok2->astOperand1() && (tok2->astOperand1()->str() == "[" || (tok2->astOperand1()->astOperand1() && tok2->astOperand1()->astOperand1()->str() == "[")))
@@ -187,7 +187,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, nonneg int varid) const
{
- if (mTokenizer_->isCPP() && tok->str() == "delete" && tok->astOperand1()) {
+ if (tok->isCpp() && tok->str() == "delete" && tok->astOperand1()) {
const Token* vartok = tok->astOperand1();
if (Token::Match(vartok, ".|::"))
vartok = vartok->astOperand2();
@@ -973,7 +973,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
continue;
const std::string& functionName = tok->str();
- if ((mTokenizer->isCPP() && functionName == "delete") ||
+ if ((tok->isCpp() && functionName == "delete") ||
functionName == "return")
continue;
@@ -989,7 +989,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
if (arg->isOp() && !(tok->isKeyword() && arg->str() == "*")) // e.g. switch (*new int)
continue;
while (arg->astOperand1()) {
- if (mTokenizer->isCPP() && Token::simpleMatch(arg, "new"))
+ if (arg->isCpp() && Token::simpleMatch(arg, "new"))
break;
arg = arg->astOperand1();
}
@@ -1031,7 +1031,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
{
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
- const bool isNew = mTokenizer->isCPP() && tok->str() == "new";
+ const bool isNew = tok->isCpp() && tok->str() == "new";
if (!isNew && !Token::Match(tok, "%name% ("))
continue;
diff --git a/lib/checkother.cpp b/lib/checkother.cpp
index 6eb877a6b70..dcc6b444665 100644
--- a/lib/checkother.cpp
+++ b/lib/checkother.cpp
@@ -92,7 +92,7 @@ void CheckOther::checkCastIntToCharAndBack()
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope * scope : symbolDatabase->functionScopes) {
std::map vars;
- for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
+ for (const Token* tok = scope->bodyStart->next(); tok && tok != scope->bodyEnd; tok = tok->next()) {
// Quick check to see if any of the matches below have any chances
if (!Token::Match(tok, "%var%|EOF %comp%|="))
continue;
@@ -107,13 +107,13 @@ void CheckOther::checkCastIntToCharAndBack()
if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) {
checkCastIntToCharAndBackError(tok, tok->strAt(2));
}
- } else if (mTokenizer->isCPP() && (Token::Match(tok, "EOF %comp% ( %var% = std :: cin . get (") || Token::Match(tok, "EOF %comp% ( %var% = cin . get ("))) {
+ } else if (tok->isCpp() && (Token::Match(tok, "EOF %comp% ( %var% = std :: cin . get (") || Token::Match(tok, "EOF %comp% ( %var% = cin . get ("))) {
tok = tok->tokAt(3);
const Variable *var = tok->variable();
if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) {
checkCastIntToCharAndBackError(tok, "cin.get");
}
- } else if (mTokenizer->isCPP() && (Token::Match(tok, "%var% = std :: cin . get (") || Token::Match(tok, "%var% = cin . get ("))) {
+ } else if (tok->isCpp() && (Token::Match(tok, "%var% = std :: cin . get (") || Token::Match(tok, "%var% = cin . get ("))) {
const Variable *var = tok->variable();
if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) {
vars[tok->varId()] = "cin.get";
@@ -482,7 +482,7 @@ void CheckOther::checkRedundantAssignment()
continue;
bool inconclusive = false;
- if (mTokenizer->isCPP() && tok->astOperand1()->valueType()) {
+ if (tok->isCpp() && tok->astOperand1()->valueType()) {
// If there is a custom assignment operator => this is inconclusive
if (tok->astOperand1()->valueType()->typeScope) {
const std::string op = "operator" + tok->str();
@@ -498,7 +498,7 @@ void CheckOther::checkRedundantAssignment()
if (inconclusive && !mSettings->certainty.isEnabled(Certainty::inconclusive))
continue;
- FwdAnalysis fwdAnalysis(mTokenizer->isCPP(), mSettings->library);
+ FwdAnalysis fwdAnalysis(mSettings->library);
if (fwdAnalysis.hasOperand(tok->astOperand2(), tok->astOperand1()))
continue;
@@ -917,7 +917,7 @@ static bool isSimpleExpr(const Token* tok, const Variable* var, const Settings*
((ftok->function() && ftok->function()->isConst()) || settings->library.isFunctionConst(ftok->str(), /*pure*/ true)))
needsCheck = true;
}
- return (needsCheck && !findExpressionChanged(tok, tok->astParent(), var->scope()->bodyEnd, settings, true));
+ return (needsCheck && !findExpressionChanged(tok, tok->astParent(), var->scope()->bodyEnd, settings));
}
//---------------------------------------------------------------------------
@@ -1305,7 +1305,7 @@ void CheckOther::checkPassByReference()
if (!isRangeBasedFor && (!var->scope() || var->scope()->function->isImplicitlyVirtual()))
continue;
- if (!isVariableChanged(var, mSettings, mTokenizer->isCPP())) {
+ if (!isVariableChanged(var, mSettings)) {
passedByValueError(var, inconclusive, isRangeBasedFor);
}
}
@@ -1407,7 +1407,7 @@ void CheckOther::checkConstVariable()
continue;
if (isStructuredBindingVariable(var)) // TODO: check all bound variables
continue;
- if (isVariableChanged(var, mSettings, mTokenizer->isCPP()))
+ if (isVariableChanged(var, mSettings))
continue;
const bool hasFunction = function != nullptr;
if (!hasFunction) {
@@ -1639,7 +1639,7 @@ void CheckOther::checkConstPointer()
if (std::find(nonConstPointers.cbegin(), nonConstPointers.cend(), p) == nonConstPointers.cend()) {
const Token *start = getVariableChangedStart(p);
const int indirect = p->isArray() ? p->dimensions().size() : 1;
- if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP()))
+ if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings))
continue;
if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && !(Token::simpleMatch(p->typeEndToken(), "*") && !p->typeEndToken()->isSimplifiedTypedef()))
continue;
@@ -1818,7 +1818,7 @@ static bool isConstant(const Token* tok) {
return tok && (tok->isEnumerator() || Token::Match(tok, "%bool%|%num%|%str%|%char%|nullptr|NULL"));
}
-static bool isConstStatement(const Token *tok, bool cpp)
+static bool isConstStatement(const Token *tok)
{
if (!tok)
return false;
@@ -1840,7 +1840,7 @@ static bool isConstStatement(const Token *tok, bool cpp)
tok2 = tok2->astParent();
}
if (Token::Match(tok, "&&|%oror%"))
- return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp);
+ return isConstStatement(tok->astOperand1()) && isConstStatement(tok->astOperand2());
if (Token::Match(tok, "!|~|%cop%") && (tok->astOperand1() || tok->astOperand2()))
return true;
if (Token::simpleMatch(tok->previous(), "sizeof ("))
@@ -1848,15 +1848,15 @@ static bool isConstStatement(const Token *tok, bool cpp)
if (isCPPCast(tok)) {
if (Token::simpleMatch(tok->astOperand1(), "dynamic_cast") && Token::simpleMatch(tok->astOperand1()->linkAt(1)->previous(), "& >"))
return false;
- return isWithoutSideEffects(cpp, tok) && isConstStatement(tok->astOperand2(), cpp);
+ return isWithoutSideEffects(tok) && isConstStatement(tok->astOperand2());
}
if (tok->isCast() && tok->next() && tok->next()->isStandardType())
- return isWithoutSideEffects(cpp, tok->astOperand1()) && isConstStatement(tok->astOperand1(), cpp);
+ return isWithoutSideEffects(tok->astOperand1()) && isConstStatement(tok->astOperand1());
if (Token::simpleMatch(tok, "."))
- return isConstStatement(tok->astOperand2(), cpp);
+ return isConstStatement(tok->astOperand2());
if (Token::simpleMatch(tok, ",")) {
if (tok->astParent()) // warn about const statement on rhs at the top level
- return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp);
+ return isConstStatement(tok->astOperand1()) && isConstStatement(tok->astOperand2());
const Token* lml = previousBeforeAstLeftmostLeaf(tok); // don't warn about matrix/vector assignment (e.g. Eigen)
if (lml)
@@ -1864,14 +1864,14 @@ static bool isConstStatement(const Token *tok, bool cpp)
const Token* stream = lml;
while (stream && Token::Match(stream->astParent(), ".|[|(|*"))
stream = stream->astParent();
- return (!stream || !isLikelyStream(cpp, stream)) && isConstStatement(tok->astOperand2(), cpp);
+ return (!stream || !isLikelyStream(stream)) && isConstStatement(tok->astOperand2());
}
if (Token::simpleMatch(tok, "?") && Token::simpleMatch(tok->astOperand2(), ":")) // ternary operator
- return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2()->astOperand1(), cpp) && isConstStatement(tok->astOperand2()->astOperand2(), cpp);
- if (isBracketAccess(tok) && isWithoutSideEffects(cpp, tok->astOperand1(), /*checkArrayAccess*/ true, /*checkReference*/ false)) {
+ return isConstStatement(tok->astOperand1()) && isConstStatement(tok->astOperand2()->astOperand1()) && isConstStatement(tok->astOperand2()->astOperand2());
+ if (isBracketAccess(tok) && isWithoutSideEffects(tok->astOperand1(), /*checkArrayAccess*/ true, /*checkReference*/ false)) {
if (Token::simpleMatch(tok->astParent(), "["))
- return isConstStatement(tok->astOperand2(), cpp) && isConstStatement(tok->astParent(), cpp);
- return isConstStatement(tok->astOperand2(), cpp);
+ return isConstStatement(tok->astOperand2()) && isConstStatement(tok->astParent());
+ return isConstStatement(tok->astOperand2());
}
return false;
}
@@ -1955,7 +1955,7 @@ void CheckOther::checkIncompleteStatement()
const Token *rtok = nextAfterAstRightmostLeaf(tok);
if (!Token::simpleMatch(tok->astParent(), ";") && !Token::simpleMatch(rtok, ";") &&
!Token::Match(tok->previous(), ";|}|{ %any% ;") &&
- !(mTokenizer->isCPP() && tok->isCast() && !tok->astParent()) &&
+ !(tok->isCpp() && tok->isCast() && !tok->astParent()) &&
!Token::simpleMatch(tok->tokAt(-2), "for (") &&
!Token::Match(tok->tokAt(-1), "%var% [") &&
!(tok->str() == "," && tok->astParent() && tok->astParent()->isAssignmentOp()))
@@ -1963,11 +1963,11 @@ void CheckOther::checkIncompleteStatement()
// Skip statement expressions
if (Token::simpleMatch(rtok, "; } )"))
continue;
- if (!isConstStatement(tok, mTokenizer->isCPP()))
+ if (!isConstStatement(tok))
continue;
if (isVoidStmt(tok))
continue;
- if (mTokenizer->isCPP() && tok->str() == "&" && !(tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isIntegral()))
+ if (tok->isCpp() && tok->str() == "&" && !(tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isIntegral()))
// Possible archive
continue;
const bool inconclusive = tok->isConstOp();
@@ -2152,7 +2152,7 @@ void CheckOther::checkMisusedScopedObject()
if (Token::simpleMatch(parTok, "<") && parTok->link())
parTok = parTok->link()->next();
if (const Token* arg = parTok->astOperand2()) {
- if (!isConstStatement(arg, mTokenizer->isCPP()))
+ if (!isConstStatement(arg))
continue;
if (parTok->str() == "(") {
if (arg->varId() && !(arg->variable() && arg->variable()->nameToken() != arg))
@@ -2275,8 +2275,8 @@ void CheckOther::checkDuplicateBranch()
if (branchTop1->str() != branchTop2->str())
continue;
ErrorPath errorPath;
- if (isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) &&
- isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings->library, true, true, &errorPath))
+ if (isSameExpression(false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) &&
+ isSameExpression(false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings->library, true, true, &errorPath))
duplicateBranchError(scope.classDef, scope.bodyEnd->next(), std::move(errorPath));
}
}
@@ -2309,10 +2309,10 @@ void CheckOther::checkInvalidFree()
const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope * scope : symbolDatabase->functionScopes) {
- for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
+ for (const Token* tok = scope->bodyStart->next(); tok && tok != scope->bodyEnd; tok = tok->next()) {
// Keep track of which variables were assigned addresses to newly-allocated memory
- if ((mTokenizer->isCPP() && Token::Match(tok, "%var% = new")) ||
+ if ((tok->isCpp() && Token::Match(tok, "%var% = new")) ||
(Token::Match(tok, "%var% = %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)))) {
allocation.insert(std::make_pair(tok->varId(), tok->strAt(2)));
inconclusive.insert(std::make_pair(tok->varId(), false));
@@ -2440,8 +2440,6 @@ void CheckOther::checkDuplicateExpression()
std::list constFunctions;
getConstFunctions(symbolDatabase, constFunctions);
- const bool cpp = mTokenizer->isCPP();
-
for (const Scope *scope : symbolDatabase->functionScopes) {
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
if (tok->str() == "=" && Token::Match(tok->astOperand1(), "%var%")) {
@@ -2466,8 +2464,8 @@ void CheckOther::checkDuplicateExpression()
Token::Match(tok->astOperand2()->previous(), "%name% (")
) &&
tok->next()->tokType() != Token::eType &&
- isSameExpression(cpp, true, tok->next(), nextAssign->next(), mSettings->library, true, false) &&
- isSameExpression(cpp, true, tok->astOperand2(), nextAssign->astOperand2(), mSettings->library, true, false) &&
+ isSameExpression(true, tok->next(), nextAssign->next(), mSettings->library, true, false) &&
+ isSameExpression(true, tok->astOperand2(), nextAssign->astOperand2(), mSettings->library, true, false) &&
tok->astOperand2()->expressionString() == nextAssign->astOperand2()->expressionString()) {
bool differentDomain = false;
const Scope * varScope = var1->scope() ? var1->scope() : scope;
@@ -2481,8 +2479,7 @@ void CheckOther::checkDuplicateExpression()
if (assignTok->astOperand1()->varId() != var1->varId() &&
assignTok->astOperand1()->varId() != var2->varId() &&
- !isSameExpression(cpp,
- true,
+ !isSameExpression(true,
tok->astOperand2(),
assignTok->astOperand1(),
mSettings->library,
@@ -2491,8 +2488,7 @@ void CheckOther::checkDuplicateExpression()
continue;
if (assignTok->astOperand2()->varId() != var1->varId() &&
assignTok->astOperand2()->varId() != var2->varId() &&
- !isSameExpression(cpp,
- true,
+ !isSameExpression(true,
tok->astOperand2(),
assignTok->astOperand2(),
mSettings->library,
@@ -2522,24 +2518,23 @@ void CheckOther::checkDuplicateExpression()
const bool pointerDereference = (tok->astOperand1() && tok->astOperand1()->isUnaryOp("*")) ||
(tok->astOperand2() && tok->astOperand2()->isUnaryOp("*"));
const bool followVar = (!isConstVarExpression(tok) || Token::Match(tok, "%comp%|%oror%|&&")) && !pointerDereference;
- if (isSameExpression(cpp,
- true,
+ if (isSameExpression(true,
tok->astOperand1(),
tok->astOperand2(),
mSettings->library,
true,
followVar,
&errorPath)) {
- if (isWithoutSideEffects(cpp, tok->astOperand1())) {
+ if (isWithoutSideEffects(tok->astOperand1())) {
const Token* loopTok = isInLoopCondition(tok);
if (!loopTok ||
- !findExpressionChanged(tok, tok, loopTok->link()->next()->link(), mSettings, cpp)) {
+ !findExpressionChanged(tok, tok, loopTok->link()->next()->link(), mSettings)) {
const bool isEnum = tok->scope()->type == Scope::eEnum;
const bool assignment = !isEnum && tok->str() == "=";
if (assignment)
selfAssignmentError(tok, tok->astOperand1()->expressionString());
else if (!isEnum) {
- if (cpp && mSettings->standards.cpp >= Standards::CPP11 && tok->str() == "==") {
+ if (tok->isCpp() && mSettings->standards.cpp >= Standards::CPP11 && tok->str() == "==") {
const Token* parent = tok->astParent();
while (parent && parent->astParent()) {
parent = parent->astParent();
@@ -2553,43 +2548,40 @@ void CheckOther::checkDuplicateExpression()
}
}
} else if (tok->str() == "=" && Token::simpleMatch(tok->astOperand2(), "=") &&
- isSameExpression(cpp,
- false,
+ isSameExpression(false,
tok->astOperand1(),
tok->astOperand2()->astOperand1(),
mSettings->library,
true,
false)) {
- if (isWithoutSideEffects(cpp, tok->astOperand1())) {
+ if (isWithoutSideEffects(tok->astOperand1())) {
selfAssignmentError(tok, tok->astOperand1()->expressionString());
}
- } else if (isOppositeExpression(cpp,
- tok->astOperand1(),
+ } else if (isOppositeExpression(tok->astOperand1(),
tok->astOperand2(),
mSettings->library,
false,
true,
&errorPath) &&
!Token::Match(tok, "=|-|-=|/|/=") &&
- isWithoutSideEffects(cpp, tok->astOperand1())) {
+ isWithoutSideEffects(tok->astOperand1())) {
oppositeExpressionError(tok, std::move(errorPath));
} else if (!Token::Match(tok, "[-/%]")) { // These operators are not associative
if (tok->astOperand2() && tok->str() == tok->astOperand1()->str() &&
- isSameExpression(cpp,
- true,
+ isSameExpression(true,
tok->astOperand2(),
tok->astOperand1()->astOperand2(),
mSettings->library,
true,
followVar,
&errorPath) &&
- isWithoutSideEffects(cpp, tok->astOperand2()))
+ isWithoutSideEffects(tok->astOperand2()))
duplicateExpressionError(tok->astOperand2(), tok->astOperand1()->astOperand2(), tok, errorPath);
- else if (tok->astOperand2() && isConstExpression(tok->astOperand1(), mSettings->library, cpp)) {
+ else if (tok->astOperand2() && isConstExpression(tok->astOperand1(), mSettings->library)) {
auto checkDuplicate = [&](const Token* exp1, const Token* exp2, const Token* ast1) {
- if (isSameExpression(cpp, true, exp1, exp2, mSettings->library, true, true, &errorPath) &&
- isWithoutSideEffects(cpp, exp1) &&
- isWithoutSideEffects(cpp, ast1->astOperand2()))
+ if (isSameExpression(true, exp1, exp2, mSettings->library, true, true, &errorPath) &&
+ isWithoutSideEffects(exp1) &&
+ isWithoutSideEffects(ast1->astOperand2()))
duplicateExpressionError(exp1, exp2, tok, errorPath, /*hasMultipleExpr*/ true);
};
const Token *ast1 = tok->astOperand1();
@@ -2603,10 +2595,10 @@ void CheckOther::checkDuplicateExpression()
}
} else if (tok->astOperand1() && tok->astOperand2() && tok->str() == ":" && tok->astParent() && tok->astParent()->str() == "?") {
if (!tok->astOperand1()->values().empty() && !tok->astOperand2()->values().empty() && isEqualKnownValue(tok->astOperand1(), tok->astOperand2()) &&
- !isVariableChanged(tok->astParent(), /*indirect*/ 0, mSettings, cpp) &&
- isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp))
+ !isVariableChanged(tok->astParent(), /*indirect*/ 0, mSettings) &&
+ isConstStatement(tok->astOperand1()) && isConstStatement(tok->astOperand2()))
duplicateValueTernaryError(tok);
- else if (isSameExpression(cpp, true, tok->astOperand1(), tok->astOperand2(), mSettings->library, false, true, &errorPath))
+ else if (isSameExpression(true, tok->astOperand1(), tok->astOperand2(), mSettings->library, false, true, &errorPath))
duplicateExpressionTernaryError(tok, std::move(errorPath));
}
}
@@ -2883,7 +2875,7 @@ void CheckOther::checkRedundantCopy()
for (const Variable* var : symbolDatabase->variableList()) {
if (!var || var->isReference() || var->isPointer() ||
(!var->type() && !var->isStlType()) || // bailout if var is of standard type, if it is a pointer or non-const
- (!var->isConst() && isVariableChanged(var, mSettings, mTokenizer->isCPP())))
+ (!var->isConst() && isVariableChanged(var, mSettings)))
continue;
const Token* startTok = var->nameToken();
@@ -2908,9 +2900,9 @@ void CheckOther::checkRedundantCopy()
const Token* dot = tok->astOperand1();
if (Token::simpleMatch(dot, ".")) {
- if (dot->astOperand1() && isVariableChanged(dot->astOperand1()->variable(), mSettings, mTokenizer->isCPP()))
+ if (dot->astOperand1() && isVariableChanged(dot->astOperand1()->variable(), mSettings))
continue;
- if (isTemporary(/*cpp*/ true, dot, &mSettings->library, /*unknown*/ true))
+ if (isTemporary(dot, &mSettings->library, /*unknown*/ true))
continue;
}
if (exprDependsOnThis(tok->previous()))
@@ -2964,7 +2956,7 @@ void CheckOther::checkNegativeBitwiseShift()
continue;
// don't warn if lhs is a class. this is an overloaded operator then
- if (mTokenizer->isCPP()) {
+ if (tok->isCpp()) {
const ValueType * lhsType = tok->astOperand1()->valueType();
if (!lhsType || !lhsType->isIntegral())
continue;
@@ -3342,9 +3334,9 @@ void CheckOther::checkEvaluationOrder()
if (tok2 == tok &&
tok->str() == "=" &&
parent->str() == "=" &&
- isSameExpression(mTokenizer->isCPP(), false, tok->astOperand1(), parent->astOperand1(), mSettings->library, true, false)) {
+ isSameExpression(false, tok->astOperand1(), parent->astOperand1(), mSettings->library, true, false)) {
if (mSettings->severity.isEnabled(Severity::warning) &&
- isSameExpression(mTokenizer->isCPP(), true, tok->astOperand1(), parent->astOperand1(), mSettings->library, true, false))
+ isSameExpression(true, tok->astOperand1(), parent->astOperand1(), mSettings->library, true, false))
selfAssignmentError(parent, tok->astOperand1()->expressionString());
break;
}
@@ -3357,7 +3349,7 @@ void CheckOther::checkEvaluationOrder()
return ChildrenToVisit::none; // don't handle address-of for now
if (tok3->str() == "(" && Token::simpleMatch(tok3->previous(), "sizeof"))
return ChildrenToVisit::none; // don't care about sizeof usage
- if (isSameExpression(mTokenizer->isCPP(), false, tok->astOperand1(), tok3, mSettings->library, true, false))
+ if (isSameExpression(false, tok->astOperand1(), tok3, mSettings->library, true, false))
foundError = true;
return foundError ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2;
});
@@ -3408,7 +3400,7 @@ void CheckOther::checkAccessOfMovedVariable()
else
inconclusive = true;
} else {
- const ExprUsage usage = getExprUsage(tok, 0, mSettings, mTokenizer->isCPP());
+ const ExprUsage usage = getExprUsage(tok, 0, mSettings);
if (usage == ExprUsage::Used)
accessOfMoved = true;
if (usage == ExprUsage::PassedByReference)
@@ -3714,7 +3706,7 @@ void CheckOther::checkKnownArgument()
continue;
if (tok->isComparisonOp() &&
isSameExpression(
- mTokenizer->isCPP(), true, tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true))
+ true, tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true))
continue;
// ensure that there is a integer variable in expression with unknown value
const Token* vartok = nullptr;
@@ -3847,10 +3839,10 @@ void CheckOther::checkComparePointers()
continue;
if (var1->isRValueReference() || var2->isRValueReference())
continue;
- if (const Token* parent2 = getParentLifetime(mTokenizer->isCPP(), v2.tokvalue, &mSettings->library))
+ if (const Token* parent2 = getParentLifetime(v2.tokvalue, &mSettings->library))
if (var1 == parent2->variable())
continue;
- if (const Token* parent1 = getParentLifetime(mTokenizer->isCPP(), v1.tokvalue, &mSettings->library))
+ if (const Token* parent1 = getParentLifetime(v1.tokvalue, &mSettings->library))
if (var2 == parent1->variable())
continue;
comparePointersError(tok, &v1, &v2);
@@ -4007,7 +3999,7 @@ void CheckOther::checkOverlappingWrite()
constexpr bool macro = true;
constexpr bool pure = true;
constexpr bool follow = true;
- if (!isSameExpression(mTokenizer->isCPP(), macro, ptr1, ptr2, mSettings->library, pure, follow, &errorPath))
+ if (!isSameExpression(macro, ptr1, ptr2, mSettings->library, pure, follow, &errorPath))
continue;
overlappingWriteFunction(tok);
}
@@ -4032,7 +4024,7 @@ void CheckOther::checkOverlappingWrite()
constexpr bool macro = true;
constexpr bool pure = true;
constexpr bool follow = true;
- if (!isSameExpression(mTokenizer->isCPP(), macro, buf1, buf2, mSettings->library, pure, follow, &errorPath))
+ if (!isSameExpression(macro, buf1, buf2, mSettings->library, pure, follow, &errorPath))
continue;
overlappingWriteFunction(tok);
}
diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp
index 848b8946cbe..2a3cbaaad56 100644
--- a/lib/checksizeof.cpp
+++ b/lib/checksizeof.cpp
@@ -236,7 +236,8 @@ void CheckSizeof::checkSizeofForPointerSize()
continue;
// Now check for the sizeof usage: Does the level of pointer indirection match?
- if (tokSize->linkAt(1)->strAt(-1) == "*") {
+ const Token * const tokLink = tokSize->linkAt(1);
+ if (tokLink && tokLink->strAt(-1) == "*") {
if (variable && variable->valueType() && variable->valueType()->pointer == 1 && variable->valueType()->type != ValueType::VOID)
sizeofForPointerError(variable, variable->str());
else if (variable2 && variable2->valueType() && variable2->valueType()->pointer == 1 && variable2->valueType()->type != ValueType::VOID)
diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp
index 3f740c2a98f..5eca694028f 100644
--- a/lib/checkstl.cpp
+++ b/lib/checkstl.cpp
@@ -283,7 +283,7 @@ bool CheckStl::isContainerSize(const Token *containerToken, const Token *expr) c
return false;
if (!Token::Match(expr->astOperand1(), ". %name% ("))
return false;
- if (!isSameExpression(mTokenizer->isCPP(), false, containerToken, expr->astOperand1()->astOperand1(), mSettings->library, false, false))
+ if (!isSameExpression(false, containerToken, expr->astOperand1()->astOperand1(), mSettings->library, false, false))
return false;
return containerToken->valueType()->container->getYield(expr->previous()->str()) == Library::Container::Yield::SIZE;
}
@@ -708,8 +708,8 @@ static bool isSameIteratorContainerExpression(const Token* tok1,
const Library& library,
ValueFlow::Value::LifetimeKind kind = ValueFlow::Value::LifetimeKind::Iterator)
{
- if (isSameExpression(true, false, tok1, tok2, library, false, false)) {
- return !astIsContainerOwned(tok1) || !isTemporary(true, tok1, &library);
+ if (isSameExpression(false, tok1, tok2, library, false, false)) {
+ return !astIsContainerOwned(tok1) || !isTemporary(tok1, &library);
}
if (astContainerYield(tok2) == Library::Container::Yield::ITEM)
return true;
@@ -718,7 +718,7 @@ static bool isSameIteratorContainerExpression(const Token* tok1,
const auto address2 = getAddressContainer(tok2);
return std::any_of(address1.begin(), address1.end(), [&](const Token* tok1) {
return std::any_of(address2.begin(), address2.end(), [&](const Token* tok2) {
- return isSameExpression(true, false, tok1, tok2, library, false, false);
+ return isSameExpression(false, tok1, tok2, library, false, false);
});
});
}
@@ -826,7 +826,7 @@ void CheckStl::mismatchingContainers()
if (iter1.tok == iter2.tok)
continue;
if (iter1.info->first && iter2.info->last &&
- isSameExpression(true, false, iter1.tok, iter2.tok, mSettings->library, false, false))
+ isSameExpression(false, iter1.tok, iter2.tok, mSettings->library, false, false))
sameIteratorExpressionError(iter1.tok);
if (checkIteratorPair(iter1.tok, iter2.tok))
return;
@@ -1662,8 +1662,8 @@ static const Token *findInsertValue(const Token *tok, const Token *containerTok,
}
if (!ikeyTok || !icontainerTok)
return nullptr;
- if (isSameExpression(true, true, containerTok, icontainerTok, library, true, false) &&
- isSameExpression(true, true, keyTok, ikeyTok, library, true, true)) {
+ if (isSameExpression(true, containerTok, icontainerTok, library, true, false) &&
+ isSameExpression(true, keyTok, ikeyTok, library, true, true)) {
if (ivalueTok)
return ivalueTok;
return ikeyTok;
@@ -1707,7 +1707,7 @@ void CheckStl::checkFindInsert()
findInsertValue(thenTok->link()->tokAt(2), containerTok, keyTok, mSettings->library);
if (!valueTok2)
continue;
- if (isSameExpression(true, true, valueTok, valueTok2, mSettings->library, true, true)) {
+ if (isSameExpression(true, valueTok, valueTok2, mSettings->library, true, true)) {
checkFindInsertError(valueTok);
}
} else {
@@ -2585,9 +2585,9 @@ static const Token *singleAssignInScope(const Token *start, nonneg int varid, bo
if (!Token::Match(start->next(), "%var% %assign%"))
return nullptr;
const Token *assignTok = start->tokAt(2);
- if (isVariableChanged(assignTok->next(), endStatement, assignTok->astOperand1()->varId(), /*globalvar*/ false, settings, /*cpp*/ true))
+ if (isVariableChanged(assignTok->next(), endStatement, assignTok->astOperand1()->varId(), /*globalvar*/ false, settings))
return nullptr;
- if (isVariableChanged(assignTok->next(), endStatement, varid, /*globalvar*/ false, settings, /*cpp*/ true))
+ if (isVariableChanged(assignTok->next(), endStatement, varid, /*globalvar*/ false, settings))
return nullptr;
input = Token::findmatch(assignTok->next(), "%varid%", endStatement, varid) || !Token::Match(start->next(), "%var% =");
hasBreak = Token::simpleMatch(endStatement->previous(), "break");
@@ -2611,7 +2611,7 @@ static const Token *singleMemberCallInScope(const Token *start, nonneg int varid
if (!Token::findmatch(dotTok->tokAt(2), "%varid%", endStatement, varid))
return nullptr;
input = Token::Match(start->next(), "%var% . %name% ( %varid% )", varid);
- if (isVariableChanged(dotTok->next(), endStatement, dotTok->astOperand1()->varId(), /*globalvar*/ false, settings, /*cpp*/ true))
+ if (isVariableChanged(dotTok->next(), endStatement, dotTok->astOperand1()->varId(), /*globalvar*/ false, settings))
return nullptr;
return dotTok;
}
@@ -2648,7 +2648,7 @@ static const Token *singleConditionalInScope(const Token *start, nonneg int vari
return nullptr;
if (!Token::findmatch(start, "%varid%", bodyTok, varid))
return nullptr;
- if (isVariableChanged(start, bodyTok, varid, /*globalvar*/ false, settings, /*cpp*/ true))
+ if (isVariableChanged(start, bodyTok, varid, /*globalvar*/ false, settings))
return nullptr;
return bodyTok;
}
@@ -2763,7 +2763,7 @@ namespace {
return true;
if (inconclusive)
return true;
- if (isVariableChanged(tok, i, settings, true))
+ if (isVariableChanged(tok, i, settings))
return true;
}
return false;
@@ -2881,7 +2881,7 @@ void CheckStl::useStlAlgorithm()
auto isConditionWithoutSideEffects = [this](const Token* tok) -> bool {
if (!Token::simpleMatch(tok, "{") || !Token::simpleMatch(tok->previous(), ")"))
return false;
- return isConstExpression(tok->previous()->link()->astOperand2(), mSettings->library, true);
+ return isConstExpression(tok->previous()->link()->astOperand2(), mSettings->library);
};
for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) {
diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp
index cc9a5939896..1c51fa5d8b9 100644
--- a/lib/checkstring.cpp
+++ b/lib/checkstring.cpp
@@ -189,7 +189,7 @@ void CheckString::checkSuspiciousStringCompare()
continue;
const ValueType* varType = varTok->valueType();
- if (mTokenizer->isCPP() && (!varType || !varType->isIntegral()))
+ if (varTok->isCpp() && (!varType || !varType->isIntegral()))
continue;
if (litTok->tokType() == Token::eString) {
@@ -396,7 +396,7 @@ void CheckString::overlappingStrcmp()
if (args1[1]->isLiteral() &&
args2[1]->isLiteral() &&
args1[1]->str() != args2[1]->str() &&
- isSameExpression(mTokenizer->isCPP(), true, args1[0], args2[0], mSettings->library, true, false))
+ isSameExpression(true, args1[0], args2[0], mSettings->library, true, false))
overlappingStrcmpError(eq0, ne0);
}
}
@@ -444,8 +444,7 @@ void CheckString::sprintfOverlappingData()
while (arg->isCast())
arg = arg->astOperand2() ? arg->astOperand2() : arg->astOperand1();
- const bool same = isSameExpression(mTokenizer->isCPP(),
- false,
+ const bool same = isSameExpression(false,
dest,
arg,
mSettings->library,
diff --git a/lib/checktype.cpp b/lib/checktype.cpp
index 344f752f96d..0cc91ac8976 100644
--- a/lib/checktype.cpp
+++ b/lib/checktype.cpp
@@ -68,7 +68,7 @@ void CheckType::checkTooBigBitwiseShift()
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
// C++ and macro: OUT(x<isCPP() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function())
+ if (tok->isCpp() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function())
tok = tok->linkAt(2);
if (!tok->astOperand1() || !tok->astOperand2())
@@ -133,7 +133,7 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
{
constexpr char id[] = "shiftTooManyBitsSigned";
- const bool cpp14 = mSettings->standards.cpp >= Standards::CPP14;
+ const bool cpp14 = ((tok && tok->isCpp()) || (mTokenizer && mTokenizer->isCPP())) && (mSettings->standards.cpp >= Standards::CPP14);
std::string behaviour = "undefined";
if (cpp14)
diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp
index e12e8047ed9..0cb2065760b 100644
--- a/lib/checkuninitvar.cpp
+++ b/lib/checkuninitvar.cpp
@@ -725,7 +725,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
if (!membervar.empty()) {
if (!suppressErrors && Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar && Token::Match(tok->next()->astParent(), "%cop%|return|throw|?"))
uninitStructMemberError(tok, tok->str() + "." + membervar);
- else if (mTokenizer->isCPP() && !suppressErrors && Token::Match(tok, "%name%") && Token::Match(tok->astParent(), "return|throw|?")) {
+ else if (tok->isCpp() && !suppressErrors && Token::Match(tok, "%name%") && Token::Match(tok->astParent(), "return|throw|?")) {
if (std::any_of(tok->values().cbegin(), tok->values().cend(), [](const ValueFlow::Value& v) {
return v.isUninitValue() && !v.isInconclusive();
}))
@@ -1306,7 +1306,7 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, const Library&
// Stream read/write
// FIXME this code is a hack!!
if (cpp && Token::Match(valueExpr->astParent(), "<<|>>")) {
- if (isLikelyStreamRead(cpp, vartok->previous()))
+ if (isLikelyStreamRead(vartok->previous()))
return nullptr;
if (const auto* vt = valueExpr->valueType()) {
@@ -1317,7 +1317,7 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, const Library&
return nullptr;
}
}
- if (astIsRhs(derefValue) && isLikelyStreamRead(cpp, derefValue->astParent()))
+ if (astIsRhs(derefValue) && isLikelyStreamRead(derefValue->astParent()))
return nullptr;
// Assignment with overloaded &
@@ -1428,7 +1428,7 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
return true;
if (Token::Match(tok->tokAt(-2), "[(,=] &"))
return true;
- if (isLikelyStreamRead(mTokenizer->isCPP(), tok->previous()))
+ if (isLikelyStreamRead(tok->previous()))
return true;
if ((tok->previous() && tok->previous()->isConstOp()) || Token::Match(tok->previous(), "[|="))
; // member variable usage
@@ -1647,7 +1647,7 @@ void CheckUninitVar::valueFlowUninit()
if (!isleaf && Token::Match(tok->astParent(), ". %name%") && (tok->astParent()->next()->varId() || tok->astParent()->next()->isEnumerator()))
continue;
}
- const ExprUsage usage = getExprUsage(tok, v->indirect, mSettings, mTokenizer->isCPP());
+ const ExprUsage usage = getExprUsage(tok, v->indirect, mSettings);
if (usage == ExprUsage::NotUsed || usage == ExprUsage::Inconclusive)
continue;
if (!v->subexpressions.empty() && usage == ExprUsage::PassedByReference)
@@ -1658,7 +1658,7 @@ void CheckUninitVar::valueFlowUninit()
continue;
if (usage != ExprUsage::Used) {
if (!(Token::Match(tok->astParent(), ". %name% (|[") && uninitderef) &&
- isVariableChanged(tok, v->indirect, mSettings, mTokenizer->isCPP()))
+ isVariableChanged(tok, v->indirect, mSettings))
continue;
if (isVariableChangedByFunctionCall(tok, v->indirect, mSettings, &inconclusive) || inconclusive)
continue;
diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp
index d7e4f4bf55e..7d7ccd7b023 100644
--- a/lib/checkunusedvar.cpp
+++ b/lib/checkunusedvar.cpp
@@ -837,7 +837,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
}
// Freeing memory (not considered "using" the pointer if it was also allocated in this function)
if ((Token::Match(tok, "%name% ( %var% )") && mSettings->library.getDeallocFuncInfo(tok)) ||
- (mTokenizer->isCPP() && (Token::Match(tok, "delete %var% ;") || Token::Match(tok, "delete [ ] %var% ;")))) {
+ (tok->isCpp() && (Token::Match(tok, "delete %var% ;") || Token::Match(tok, "delete [ ] %var% ;")))) {
nonneg int varid = 0;
if (tok->str() != "delete") {
const Token *varTok = tok->tokAt(2);
@@ -953,8 +953,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
const Token *type = allocFuncCallToken->next();
// skip nothrow
- if (mTokenizer->isCPP() && (Token::simpleMatch(type, "( nothrow )") ||
- Token::simpleMatch(type, "( std :: nothrow )")))
+ if (type->isCpp() && (Token::simpleMatch(type, "( nothrow )") ||
+ Token::simpleMatch(type, "( std :: nothrow )")))
type = type->link()->next();
// is it a user defined type?
@@ -1026,7 +1026,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
if (var) {
// Consider allocating memory separately because allocating/freeing alone does not constitute using the variable
if (var->mType == Variables::pointer &&
- ((mTokenizer->isCPP() && Token::simpleMatch(skipBrackets(tok->next()), "= new")) ||
+ ((tok->isCpp() && Token::simpleMatch(skipBrackets(tok->next()), "= new")) ||
(Token::Match(skipBrackets(tok->next()), "= %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2))))) {
variables.allocateMemory(varid, tok);
} else if (var->mType == Variables::pointer || var->mType == Variables::reference) {
@@ -1039,7 +1039,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
}
}
- else if (mTokenizer->isCPP() && Token::Match(tok, "[;{}] %var% <<")) {
+ else if (tok->isCpp() && Token::Match(tok, "[;{}] %var% <<")) {
variables.erase(tok->next()->varId());
}
@@ -1049,13 +1049,13 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
} else // addressof
variables.use(tok->next()->varId(), tok); // use = read + write
} else if (Token::Match(tok, ">>|>>= %name%")) {
- if (isLikelyStreamRead(mTokenizer->isCPP(), tok))
+ if (isLikelyStreamRead(tok))
variables.use(tok->next()->varId(), tok); // use = read + write
else
variables.read(tok->next()->varId(), tok);
} else if (Token::Match(tok, "%var% >>|&") && Token::Match(tok->previous(), "[{};:]")) {
variables.read(tok->varId(), tok);
- } else if (isLikelyStreamRead(mTokenizer->isCPP(),tok->previous())) {
+ } else if (isLikelyStreamRead(tok->previous())) {
variables.use(tok->varId(), tok);
}
@@ -1205,13 +1205,13 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (isIncrementOrDecrement && tok->astParent() && precedes(tok, tok->astOperand1()))
continue;
- if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false))
+ if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), tok->isCpp(), false))
continue;
const bool isPointer = tok->valueType() && (tok->valueType()->pointer || tok->valueType()->type == ValueType::SMART_POINTER);
if (tok->isName()) {
- if (isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false))
+ if (isRaiiClass(tok->valueType(), tok->isCpp(), false))
continue;
tok = tok->next();
}
@@ -1298,7 +1298,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == Scope::eUnion)
continue;
- FwdAnalysis fwdAnalysis(mTokenizer->isCPP(), mSettings->library);
+ FwdAnalysis fwdAnalysis(mSettings->library);
const Token* scopeEnd = ValueFlow::getEndOfExprScope(expr, scope, /*smallest*/ false);
if (fwdAnalysis.unusedValue(expr, start, scopeEnd)) {
if (!bailoutTypeName.empty()) {
@@ -1688,7 +1688,7 @@ bool CheckUnusedVar::isFunctionWithoutSideEffects(const Function& func, const To
// check if global variable is changed
if (bodyVariable->isGlobal() || (pointersToGlobals.find(bodyVariable) != pointersToGlobals.end())) {
const int indirect = bodyVariable->isArray() ? bodyVariable->dimensions().size() : bodyVariable->isPointer();
- if (isVariableChanged(bodyToken, indirect, mSettings, mTokenizer->isCPP())) {
+ if (isVariableChanged(bodyToken, indirect, mSettings)) {
return false;
}
// check if pointer to global variable assigned to another variable (another_var = &global_var)
diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp
index 3606a4f3432..d78f8121114 100644
--- a/lib/checkvaarg.cpp
+++ b/lib/checkvaarg.cpp
@@ -150,7 +150,7 @@ void CheckVaarg::va_list_usage()
tok = findNextTokenFromBreak(tok);
if (!tok)
return;
- } else if (tok->str() == "goto" || (mTokenizer->isCPP() && tok->str() == "try")) {
+ } else if (tok->str() == "goto" || (tok->isCpp() && tok->str() == "try")) {
open = false;
break;
} else if (!open && tok->varId() == var->declarationId())
diff --git a/lib/config.h b/lib/config.h
index 060462e6474..538e20a7ad6 100644
--- a/lib/config.h
+++ b/lib/config.h
@@ -151,13 +151,13 @@ static const std::string emptyString;
#endif
#if defined(_WIN32)
-#define THREADING_MODEL_THREAD
+#define HAS_THREADING_MODEL_THREAD
#define STDCALL __stdcall
-#elif defined(USE_THREADS)
-#define THREADING_MODEL_THREAD
-#define STDCALL
#elif ((defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)) || defined(__CPPCHECK__)
-#define THREADING_MODEL_FORK
+#define HAS_THREADING_MODEL_FORK
+#if !defined(DISALLOW_THREAD_EXECUTOR)
+#define HAS_THREADING_MODEL_THREAD
+#endif
#define STDCALL
#else
#error "No threading model defined"
diff --git a/lib/ctu.cpp b/lib/ctu.cpp
index 9dd4369f533..a98e7e80943 100644
--- a/lib/ctu.cpp
+++ b/lib/ctu.cpp
@@ -436,7 +436,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
return fileInfo;
}
-static std::list> getUnsafeFunction(const Tokenizer *tokenizer, const Settings *settings, const Scope *scope, int argnr, bool (*isUnsafeUsage)(const Settings *settings, const Token *argtok, MathLib::bigint *value))
+static std::list> getUnsafeFunction(const Settings *settings, const Scope *scope, int argnr, bool (*isUnsafeUsage)(const Settings *settings, const Token *argtok, MathLib::bigint *value))
{
std::list> ret;
const Variable * const argvar = scope->function->getArgumentVar(argnr);
@@ -450,7 +450,7 @@ static std::list> getUnsafeFunction(co
int indirect = 0;
if (argvar->valueType())
indirect = argvar->valueType()->pointer;
- if (isVariableChanged(tok2->link(), tok2, indirect, argvar->declarationId(), false, settings, tokenizer->isCPP()))
+ if (isVariableChanged(tok2->link(), tok2, indirect, argvar->declarationId(), false, settings))
return ret;
}
if (Token::Match(tok2, "%oror%|&&|?")) {
@@ -482,7 +482,7 @@ std::list CTU::getUnsafeUsage(const Tokenizer *token
// "Unsafe" functions unconditionally reads data before it is written..
for (int argnr = 0; argnr < function->argCount(); ++argnr) {
- for (const std::pair &v : getUnsafeFunction(tokenizer, settings, &scope, argnr, isUnsafeUsage)) {
+ for (const std::pair &v : getUnsafeFunction(settings, &scope, argnr, isUnsafeUsage)) {
const Token *tok = v.first;
const MathLib::bigint val = v.second;
unsafeUsage.emplace_back(CTU::getFunctionId(tokenizer, function), argnr+1, tok->str(), CTU::FileInfo::Location(tokenizer,tok), val);
diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp
index 0dfe80895f8..4385e393cb8 100644
--- a/lib/forwardanalyzer.cpp
+++ b/lib/forwardanalyzer.cpp
@@ -383,13 +383,13 @@ namespace {
std::pair exprToks = stepTok->findExpressionStartEndTokens();
if (exprToks.first != nullptr && exprToks.second != nullptr)
stepChangesCond |=
- findExpressionChanged(condTok, exprToks.first, exprToks.second->next(), &settings, true) != nullptr;
+ findExpressionChanged(condTok, exprToks.first, exprToks.second->next(), &settings) != nullptr;
}
- const bool bodyChangesCond = findExpressionChanged(condTok, endBlock->link(), endBlock, &settings, true);
+ const bool bodyChangesCond = findExpressionChanged(condTok, endBlock->link(), endBlock, &settings);
// Check for mutation in the condition
const bool condChanged =
nullptr != findAstNode(condTok, [&](const Token* tok) {
- return isVariableChanged(tok, 0, &settings, true);
+ return isVariableChanged(tok, 0, &settings);
});
const bool changed = stepChangesCond || bodyChangesCond || condChanged;
if (!changed)
diff --git a/lib/fwdanalysis.cpp b/lib/fwdanalysis.cpp
index e0b3074ff0d..264153d1fd0 100644
--- a/lib/fwdanalysis.cpp
+++ b/lib/fwdanalysis.cpp
@@ -272,12 +272,12 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
if (exprVarIds.find(tok->varId()) != exprVarIds.end()) {
const Token *parent = tok;
bool other = false;
- bool same = tok->astParent() && isSameExpression(mCpp, false, expr, tok, mLibrary, true, false, nullptr);
+ bool same = tok->astParent() && isSameExpression(false, expr, tok, mLibrary, true, false, nullptr);
while (!same && Token::Match(parent->astParent(), "*|.|::|[|(|%cop%")) {
parent = parent->astParent();
if (parent->str() == "(" && !parent->isCast())
break;
- if (isSameExpression(mCpp, false, expr, parent, mLibrary, true, false, nullptr)) {
+ if (isSameExpression(false, expr, parent, mLibrary, true, false, nullptr)) {
same = true;
if (mWhat == What::ValueFlow) {
KnownAndToken v;
@@ -287,7 +287,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
}
}
if (Token::Match(parent, ". %var%") && parent->next()->varId() && exprVarIds.find(parent->next()->varId()) == exprVarIds.end() &&
- isSameExpression(mCpp, false, expr->astOperand1(), parent->astOperand1(), mLibrary, true, false, nullptr)) {
+ isSameExpression(false, expr->astOperand1(), parent->astOperand1(), mLibrary, true, false, nullptr)) {
other = true;
break;
}
@@ -317,7 +317,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
if (hasGccCompoundStatement(parent->astParent()->astOperand2()))
return Result(Result::Type::BAILOUT);
// cppcheck-suppress shadowFunction - TODO: fix this
- const bool reassign = isSameExpression(mCpp, false, expr, parent, mLibrary, false, false, nullptr);
+ const bool reassign = isSameExpression(false, expr, parent, mLibrary, false, false, nullptr);
if (reassign)
return Result(Result::Type::WRITE, parent->astParent());
return Result(Result::Type::READ);
@@ -395,11 +395,6 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
return Result(Result::Type::NONE);
}
-bool FwdAnalysis::isGlobalData(const Token *expr) const
-{
- return ::isGlobalData(expr, mCpp);
-}
-
std::set FwdAnalysis::getExprVarIds(const Token* expr, bool* localOut, bool* unknownVarIdOut) const
{
// all variable ids in expr.
@@ -469,7 +464,7 @@ bool FwdAnalysis::hasOperand(const Token *tok, const Token *lhs) const
{
if (!tok)
return false;
- if (isSameExpression(mCpp, false, tok, lhs, mLibrary, false, false, nullptr))
+ if (isSameExpression(false, tok, lhs, mLibrary, false, false, nullptr))
return true;
return hasOperand(tok->astOperand1(), lhs) || hasOperand(tok->astOperand2(), lhs);
}
@@ -517,7 +512,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
if (tok->function() && tok->function()->getArgumentVar(argnr) && !tok->function()->getArgumentVar(argnr)->isReference() && !tok->function()->isConst())
continue;
for (const Token *subexpr = expr; subexpr; subexpr = subexpr->astOperand1()) {
- if (isSameExpression(mCpp, macro, subexpr, args[argnr], mLibrary, pure, followVar)) {
+ if (isSameExpression(macro, subexpr, args[argnr], mLibrary, pure, followVar)) {
const Scope* scope = expr->scope(); // if there is no other variable, assume no aliasing
if (scope->varlist.size() > 1)
return true;
@@ -542,7 +537,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
continue;
for (const Token *subexpr = expr; subexpr; subexpr = subexpr->astOperand1()) {
- if (subexpr != addrOf && isSameExpression(mCpp, macro, subexpr, addrOf, mLibrary, pure, followVar))
+ if (subexpr != addrOf && isSameExpression(macro, subexpr, addrOf, mLibrary, pure, followVar))
return true;
}
}
diff --git a/lib/fwdanalysis.h b/lib/fwdanalysis.h
index bc87ff2a597..17fc29f7b42 100644
--- a/lib/fwdanalysis.h
+++ b/lib/fwdanalysis.h
@@ -37,7 +37,7 @@ class Library;
*/
class FwdAnalysis {
public:
- FwdAnalysis(bool cpp, const Library &library) : mCpp(cpp), mLibrary(library) {}
+ explicit FwdAnalysis(const Library &library) : mLibrary(library) {}
bool hasOperand(const Token *tok, const Token *lhs) const;
@@ -82,10 +82,6 @@ class FwdAnalysis {
Result check(const Token *expr, const Token *startToken, const Token *endToken);
Result checkRecursive(const Token *expr, const Token *startToken, const Token *endToken, const std::set &exprVarIds, bool local, bool inInnerClass, int depth=0);
- // Is expression a l-value global data?
- bool isGlobalData(const Token *expr) const;
-
- const bool mCpp;
const Library &mLibrary;
enum class What { Reassign, UnusedValue, ValueFlow } mWhat = What::Reassign;
std::vector mValueFlow;
diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp
index 12b53c0acb3..e00075b0118 100644
--- a/lib/programmemory.cpp
+++ b/lib/programmemory.cpp
@@ -295,7 +295,7 @@ void programMemoryParseCondition(ProgramMemory& pm, const Token* tok, const Toke
return;
if (!truevalue.isIntValue())
return;
- if (endTok && findExpressionChanged(vartok, tok->next(), endTok, settings, true))
+ if (endTok && findExpressionChanged(vartok, tok->next(), endTok, settings))
return;
const bool impossible = (tok->str() == "==" && !then) || (tok->str() == "!=" && then);
const ValueFlow::Value& v = then ? truevalue : falsevalue;
@@ -323,7 +323,7 @@ void programMemoryParseCondition(ProgramMemory& pm, const Token* tok, const Toke
pm.setIntValue(tok, 0, then);
}
} else if (tok && tok->exprId() > 0) {
- if (endTok && findExpressionChanged(tok, tok->next(), endTok, settings, true))
+ if (endTok && findExpressionChanged(tok, tok->next(), endTok, settings))
return;
pm.setIntValue(tok, 0, then);
assert(settings);
@@ -381,7 +381,7 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
}
}
} else if (tok2->exprId() > 0 && Token::Match(tok2, ".|(|[|*|%var%") && !pm.hasValue(tok2->exprId()) &&
- isVariableChanged(tok2, 0, settings, true)) {
+ isVariableChanged(tok2, 0, settings)) {
pm.setUnknown(tok2);
}
@@ -421,7 +421,7 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
static void removeModifiedVars(ProgramMemory& pm, const Token* tok, const Token* origin)
{
pm.erase_if([&](const ExprIdToken& e) {
- return isVariableChanged(origin, tok, e.getExpressionId(), false, nullptr, true);
+ return isVariableChanged(origin, tok, e.getExpressionId(), false, nullptr);
});
}
@@ -508,7 +508,7 @@ void ProgramMemoryState::removeModifiedVars(const Token* tok)
state.erase_if([&](const ExprIdToken& e) {
const Token* start = origins[e.getExpressionId()];
const Token* expr = e.tok;
- if (!expr || findExpressionChangedSkipDeadCode(expr, start, tok, settings, true, eval)) {
+ if (!expr || findExpressionChangedSkipDeadCode(expr, start, tok, settings, eval)) {
origins.erase(e.getExpressionId());
return true;
}
@@ -1610,7 +1610,7 @@ namespace {
if (ValueFlow::isContainerSizeChanged(child, v.indirect, *settings))
v = unknown();
} else if (v.valueType != ValueFlow::Value::ValueType::UNINIT) {
- if (isVariableChanged(child, v.indirect, settings, true))
+ if (isVariableChanged(child, v.indirect, settings))
v = unknown();
}
}
diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp
index 213061e5044..a94e1679bb7 100644
--- a/lib/reverseanalyzer.cpp
+++ b/lib/reverseanalyzer.cpp
@@ -248,7 +248,7 @@ namespace {
// Assignment to
} else if (lhsAction.matches() && !assignTok->astOperand2()->hasKnownIntValue() &&
assignTok->astOperand2()->exprId() > 0 &&
- isConstExpression(assignTok->astOperand2(), settings.library, true)) {
+ isConstExpression(assignTok->astOperand2(), settings.library)) {
const std::string info = "Assignment to '" + assignTok->expressionString() + "'";
ValuePtr a = analyzer->reanalyze(assignTok->astOperand2(), info);
if (a) {
diff --git a/lib/settings.cpp b/lib/settings.cpp
index 27c4ecdebef..ae03f2476de 100644
--- a/lib/settings.cpp
+++ b/lib/settings.cpp
@@ -16,6 +16,7 @@
* along with this program. If not, see .
*/
+#include "config.h"
#include "settings.h"
#include "path.h"
#include "summaries.h"
@@ -41,6 +42,7 @@ Settings::Settings()
severity.setEnabled(Severity::error, true);
certainty.setEnabled(Certainty::normal, true);
setCheckLevelNormal();
+ executor = defaultExecutor();
}
std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppressions)
@@ -593,3 +595,14 @@ std::string Settings::getMisraRuleText(const std::string& id, const std::string&
const auto it = mMisraRuleTexts.find(id.substr(id.rfind('-') + 1));
return it != mMisraRuleTexts.end() ? it->second : text;
}
+
+Settings::ExecutorType Settings::defaultExecutor()
+{
+ static constexpr ExecutorType defaultExecutor =
+#if defined(HAS_THREADING_MODEL_FORK)
+ ExecutorType::Process;
+#elif defined(HAS_THREADING_MODEL_THREAD)
+ ExecutorType::Thread;
+#endif
+ return defaultExecutor;
+}
diff --git a/lib/settings.h b/lib/settings.h
index aad106fed50..a4aa03eee46 100644
--- a/lib/settings.h
+++ b/lib/settings.h
@@ -195,6 +195,18 @@ class CPPCHECKLIB WARN_UNUSED Settings {
bool exceptionHandling{};
#endif
+ enum class ExecutorType
+ {
+#ifdef HAS_THREADING_MODEL_THREAD
+ Thread,
+#endif
+#ifdef HAS_THREADING_MODEL_FORK
+ Process
+#endif
+ };
+
+ ExecutorType executor;
+
// argv[0]
std::string exename;
@@ -465,6 +477,8 @@ class CPPCHECKLIB WARN_UNUSED Settings {
void setMisraRuleTexts(const std::string& data);
std::string getMisraRuleText(const std::string& id, const std::string& text) const;
+ static ExecutorType defaultExecutor();
+
private:
static std::string parseEnabled(const std::string &str, std::tuple, SimpleEnableGroup> &groups);
std::string applyEnabled(const std::string &str, bool enable);
diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp
index 82466c21e4c..5b421704a49 100644
--- a/lib/symboldatabase.cpp
+++ b/lib/symboldatabase.cpp
@@ -58,8 +58,6 @@ SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, E
if (!mTokenizer.tokens())
return;
- mIsCpp = isCPP();
-
if (mSettings.platform.defaultSign == 's' || mSettings.platform.defaultSign == 'S')
mDefaultSignedness = ValueType::SIGNED;
else if (mSettings.platform.defaultSign == 'u' || mSettings.platform.defaultSign == 'U')
@@ -162,7 +160,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
"SymbolDatabase",
tok->progressValue());
// Locate next class
- if ((mTokenizer.isCPP() && tok->isKeyword() &&
+ if ((tok->isCpp() && tok->isKeyword() &&
((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
!Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) ||
(Token::Match(tok, "enum class| %name% {") ||
@@ -172,7 +170,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
if (tok->strAt(1) == "::")
tok2 = tok2->next();
- else if (mTokenizer.isCPP() && tok->strAt(1) == "class")
+ else if (tok->isCpp() && tok->strAt(1) == "class")
tok2 = tok2->next();
while (Token::Match(tok2, ":: %name%"))
@@ -188,7 +186,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// skip over final
- if (mTokenizer.isCPP() && Token::simpleMatch(tok2, "final"))
+ if (tok2 && tok2->isCpp() && Token::simpleMatch(tok2, "final"))
tok2 = tok2->next();
// make sure we have valid code
@@ -256,7 +254,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// definition may be different than declaration
- if (mTokenizer.isCPP() && tok->str() == "class") {
+ if (tok->isCpp() && tok->str() == "class") {
access[new_scope] = AccessControl::Private;
new_scope->type = Scope::eClass;
} else if (tok->str() == "struct") {
@@ -315,7 +313,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
if (new_scope->type == Scope::eEnum) {
- tok2 = new_scope->addEnum(tok, mTokenizer.isCPP());
+ tok2 = new_scope->addEnum(tok);
scope->nestedList.push_back(new_scope);
if (!tok2)
@@ -331,7 +329,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// Namespace and unknown macro (#3854)
- else if (mTokenizer.isCPP() && tok->isKeyword() &&
+ else if (tok->isCpp() && tok->isKeyword() &&
Token::Match(tok, "namespace %name% %type% (") &&
tok->tokAt(2)->isUpperCaseName() &&
Token::simpleMatch(tok->linkAt(3), ") {")) {
@@ -370,7 +368,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// using namespace
- else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "using namespace ::| %type% ;|::")) {
+ else if (tok->isCpp() && tok->isKeyword() && Token::Match(tok, "using namespace ::| %type% ;|::")) {
Scope::UsingInfo using_info;
using_info.start = tok; // save location
@@ -390,7 +388,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// using type alias
- else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "using %name% =") && !tok->tokAt(2)->isSimplifiedTypedef()) {
+ else if (tok->isCpp() && tok->isKeyword() && Token::Match(tok, "using %name% =") && !tok->tokAt(2)->isSimplifiedTypedef()) {
if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) {
// fill typeList..
typeList.emplace_back(tok, nullptr, scope);
@@ -603,7 +601,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
}
// friend class declaration?
- else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "friend class|struct| ::| %any% ;|::")) {
+ else if (tok->isCpp() && tok->isKeyword() && Token::Match(tok, "friend class|struct| ::| %any% ;|::")) {
Type::FriendInfo friendInfo;
// save the name start
@@ -1141,7 +1139,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
inTemplateArg = tok->link();
if (inTemplateArg == tok)
inTemplateArg = nullptr;
- if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{(,)>;]")) && !isReservedName(tok->str())) {
+ if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{(,)>;]")) && !isReservedName(tok)) {
if (tok->next()->str() == ">" && !tok->next()->link())
continue;
@@ -1538,7 +1536,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
// TODO: handle all C/C++ standards
if (cppkeywords.count(tok->str()) > 0)
continue;
- if (mSettings.standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0)
+ if (tok->isCpp() && (mSettings.standards.cpp >= Standards::CPP20) && cpp20keywords.count(tok->str()) > 0)
continue;
std::string fstr = tok->str();
const Token* ftok = tok->previous();
@@ -1550,7 +1548,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
}
if (mSettings.library.functions.find(fstr) != mSettings.library.functions.end())
continue;
- if (mTokenizer.isCPP()) {
+ if (tok->isCpp()) {
const Token* parent = tok->astParent();
while (Token::Match(parent, "::|[|{"))
parent = parent->astParent();
@@ -1615,7 +1613,7 @@ namespace {
}
};
using ExprIdMap = std::map;
- void setParentExprId(Token* tok, bool cpp, ExprIdMap& exprIdMap, nonneg int &id) {
+ void setParentExprId(Token* tok, ExprIdMap& exprIdMap, nonneg int &id) {
if (!tok->astParent() || tok->astParent()->isControlFlowKeyword())
return;
const Token* op1 = tok->astParent()->astOperand1();
@@ -1632,7 +1630,7 @@ namespace {
if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) {
tok->astParent()->exprId(id);
++id;
- setParentExprId(tok->astParent(), cpp, exprIdMap, id);
+ setParentExprId(tok->astParent(), exprIdMap, id);
return;
}
@@ -1674,7 +1672,7 @@ namespace {
if (key.operand1 > key.operand2 && key.operand2 &&
Token::Match(tok->astParent(), "%or%|%oror%|+|*|&|&&|^|==|!=")) {
// In C++ the order of operands of + might matter
- if (!cpp ||
+ if (!tok->isCpp() ||
key.parentOp != "+" ||
!tok->astParent()->valueType() ||
tok->astParent()->valueType()->isIntegral() ||
@@ -1691,7 +1689,7 @@ namespace {
} else {
tok->astParent()->exprId(it->second);
}
- setParentExprId(tok->astParent(), cpp, exprIdMap, id);
+ setParentExprId(tok->astParent(), exprIdMap, id);
}
}
@@ -1766,7 +1764,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
if (tok->varId() > 0) {
tok->exprId(tok->varId());
if (tok->astParent() && tok->astParent()->exprId() == 0)
- setParentExprId(tok, mTokenizer.isCPP(), exprIdMap, id);
+ setParentExprId(tok, exprIdMap, id);
} else if (tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) {
if (tok->tokType() == Token::Type::eBracket)
continue;
@@ -1789,7 +1787,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
}
}
- setParentExprId(tok, mTokenizer.isCPP(), exprIdMap, id);
+ setParentExprId(tok, exprIdMap, id);
}
}
for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
@@ -1978,7 +1976,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
return false;
// regular function?
- else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) && tok->previous() &&
+ else if (Token::Match(tok, "%name% (") && !isReservedName(tok) && tok->previous() &&
(Token::Match(tok->previous(), "%name%|>|&|&&|*|::|~") || // Either a return type or scope qualifier in front of tok
outerScope->isClassOrStructOrUnion())) { // or a ctor/dtor
const Token* tok1 = tok->previous();
@@ -2020,7 +2018,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
// done if constructor or destructor
if (!Token::Match(tok1, "{|}|;|public:|protected:|private:") && tok1) {
// skip over pointers and references
- while (Token::Match(tok1, "%type%|*|&|&&") && !endsWith(tok1->str(), ':') && (!isReservedName(tok1->str()) || tok1->str() == "const"))
+ while (Token::Match(tok1, "%type%|*|&|&&") && !endsWith(tok1->str(), ':') && (!isReservedName(tok1) || tok1->str() == "const"))
tok1 = tok1->previous();
// skip over decltype
@@ -2063,7 +2061,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
// skip over modifiers and other stuff
while (Token::Match(tok1, "const|static|extern|template|virtual|struct|class|enum|%name%")) {
// friend type func(); is not a function
- if (isCPP() && tok1->str() == "friend" && tok2->str() == ";")
+ if (tok1->isCpp() && tok1->str() == "friend" && tok2->str() == ";")
return false;
tok1 = tok1->previous();
}
@@ -2113,7 +2111,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
}
// regular C function with missing return or invalid C++ ?
- else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) &&
+ else if (Token::Match(tok, "%name% (") && !isReservedName(tok) &&
Token::simpleMatch(tok->linkAt(1), ") {") &&
(!tok->previous() || Token::Match(tok->previous(), ";|}"))) {
if (tok->isC()) {
@@ -2841,8 +2839,7 @@ static bool typesMatch(
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, nonneg int path_length) const
{
- const bool isCPP = scope->check->isCPP();
- if (!isCPP) // C does not support overloads
+ if (!first->isCpp()) // C does not support overloads
return true;
int arg_path_length = path_length;
@@ -3646,7 +3643,7 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, con
void SymbolDatabase::returnImplicitIntError(const Token *tok) const
{
- if (tok && mSettings.severity.isEnabled(Severity::portability) && mSettings.standards.c != Standards::C89 && mErrorLogger) {
+ if (tok && mSettings.severity.isEnabled(Severity::portability) && (tok->isC() && mSettings.standards.c != Standards::C89) && mErrorLogger) {
const std::list locationList(1, tok);
const ErrorMessage errmsg(locationList, &mTokenizer.list,
Severity::portability,
@@ -4757,7 +4754,7 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *
const Token *nameTok = classDef;
if (!classDef) {
type = Scope::eGlobal;
- } else if (classDef->str() == "class" && check && check->isCPP()) {
+ } else if (classDef->str() == "class" && classDef->isCpp()) {
type = Scope::eClass;
nameTok = nameTok->next();
} else if (classDef->str() == "struct") {
@@ -4969,7 +4966,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con
const Token *typestart = tok;
// C++17 structured bindings
- if (settings.standards.cpp >= Standards::CPP17 && Token::Match(tok, "auto &|&&| [")) {
+ if (tok && tok->isCpp() && (settings.standards.cpp >= Standards::CPP17) && Token::Match(tok, "auto &|&&| [")) {
const Token *typeend = Token::findsimplematch(typestart, "[")->previous();
for (tok = typeend->tokAt(2); Token::Match(tok, "%name%|,"); tok = tok->next()) {
if (tok->varId())
@@ -5068,7 +5065,7 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok,
if (!tok)
return false;
- const bool isCPP = check && check->mTokenizer.isCPP();
+ const bool isCPP = tok->isCpp();
if (isCPP && Token::Match(tok, "throw|new"))
return false;
@@ -5136,12 +5133,12 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok,
return nullptr != vartok;
}
-const Token * Scope::addEnum(const Token * tok, bool isCpp)
+const Token * Scope::addEnum(const Token * tok)
{
const Token * tok2 = tok->next();
// skip over class if present
- if (isCpp && tok2->str() == "class")
+ if (tok2->isCpp() && tok2->str() == "class")
tok2 = tok2->next();
// skip over name
@@ -5202,7 +5199,7 @@ const Token * Scope::addEnum(const Token * tok, bool isCpp)
if (tok2 == end) {
tok2 = tok2->next();
- if (tok2 && tok2->str() != ";" && (isCpp || tok2->str() != ")"))
+ if (tok2 && tok2->str() != ";" && (tok2->isCpp() || tok2->str() != ")"))
tok2 = nullptr;
} else
tok2 = nullptr;
@@ -5828,7 +5825,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
fallback2++;
// Try to evaluate the apparently more complex expression
- else if (check->isCPP()) {
+ else if (arguments[j]->isCpp()) {
const Token *vartok = arguments[j];
if (vartok->str() == ".") {
const Token* rml = nextAfterAstRightmostLeaf(vartok);
@@ -6204,13 +6201,6 @@ const Function *Scope::getDestructor() const
//---------------------------------------------------------------------------
-bool SymbolDatabase::isCPP() const
-{
- return mTokenizer.isCPP();
-}
-
-//---------------------------------------------------------------------------
-
const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const
{
const Scope *scope = nullptr;
@@ -6459,9 +6449,10 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
//---------------------------------------------------------------------------
-bool SymbolDatabase::isReservedName(const std::string& iName) const
+bool SymbolDatabase::isReservedName(const Token* tok)
{
- if (isCPP()) {
+ const std::string& iName = tok->str();
+ if (tok->isCpp()) {
static const auto& cpp_keywords = Keywords::getAll(Standards::cppstd_t::CPPLatest);
return cpp_keywords.find(iName) != cpp_keywords.cend();
}
@@ -6487,7 +6478,6 @@ static const Token* parsedecl(const Token* type,
ValueType* const valuetype,
ValueType::Sign defaultSignedness,
const Settings& settings,
- bool isCpp,
SourceLocation loc = SourceLocation::current());
void SymbolDatabase::setValueType(Token* tok, const Variable& var, const SourceLocation &loc)
@@ -6509,7 +6499,7 @@ void SymbolDatabase::setValueType(Token* tok, const Variable& var, const SourceL
valuetype.containerTypeToken = var.valueType()->containerTypeToken;
}
valuetype.smartPointerType = var.smartPointerType();
- if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) {
if (tok->str() == "." && tok->astOperand1()) {
const ValueType * const vt = tok->astOperand1()->valueType();
if (vt && (vt->constness & 1) != 0)
@@ -6588,7 +6578,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
const ValueType *vt2 = parent->astOperand2() ? parent->astOperand2()->valueType() : nullptr;
if (vt1 && Token::Match(parent, "<<|>>")) {
- if (!mIsCpp || (vt2 && vt2->isIntegral())) {
+ if (!parent->isCpp() || (vt2 && vt2->isIntegral())) {
if (vt1->type < ValueType::Type::BOOL || vt1->type >= ValueType::Type::INT) {
ValueType vt(*vt1);
vt.reference = Reference::None;
@@ -6608,7 +6598,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
if (vt1 && vt1->container && vt1->containerTypeToken && Token::Match(parent, ". %name% (") &&
isContainerYieldElement(vt1->container->getYield(parent->next()->str()))) {
ValueType item;
- if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings)) {
if (item.constness == 0)
item.constness = vt1->constness;
if (item.volatileness == 0)
@@ -6633,8 +6623,8 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
auto vt = *vt1;
vt.reference = Reference::None;
setValueType(parent, vt);
- } else if (mIsCpp && ((Token::Match(parent->tokAt(-3), "%var% ; %var% =") && parent->strAt(-3) == parent->strAt(-1)) ||
- Token::Match(parent->tokAt(-1), "%var% ="))) {
+ } else if (parent->isCpp() && ((Token::Match(parent->tokAt(-3), "%var% ; %var% =") && parent->strAt(-3) == parent->strAt(-1)) ||
+ Token::Match(parent->tokAt(-1), "%var% ="))) {
Token *var1Tok = parent->strAt(-2) == ";" ? parent->tokAt(-3) : parent->tokAt(-1);
Token *autoTok = nullptr;
if (Token::simpleMatch(var1Tok->tokAt(-1), "auto"))
@@ -6691,7 +6681,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
return;
}
- if (parent->str() == "[" && (!mIsCpp || parent->astOperand1() == tok) && valuetype.pointer > 0U && !Token::Match(parent->previous(), "[{,]")) {
+ if (parent->str() == "[" && (!parent->isCpp() || parent->astOperand1() == tok) && valuetype.pointer > 0U && !Token::Match(parent->previous(), "[{,]")) {
const Token *op1 = parent->astOperand1();
while (op1 && op1->str() == "[")
op1 = op1->astOperand1();
@@ -6726,7 +6716,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::ITERATOR &&
valuetype.containerTypeToken) {
ValueType vt;
- if (parsedecl(valuetype.containerTypeToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(valuetype.containerTypeToken, &vt, mDefaultSignedness, mSettings)) {
if (vt.constness == 0)
vt.constness = valuetype.constness;
if (vt.volatileness == 0)
@@ -6740,7 +6730,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::SMART_POINTER &&
valuetype.smartPointerTypeToken) {
ValueType vt;
- if (parsedecl(valuetype.smartPointerTypeToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(valuetype.smartPointerTypeToken, &vt, mDefaultSignedness, mSettings)) {
if (vt.constness == 0)
vt.constness = valuetype.constness;
if (vt.volatileness == 0)
@@ -6873,7 +6863,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
autovt.type = ValueType::Type::NONSTD;
}
}
- } else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings, mIsCpp)) {
+ } else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings)) {
setType = true;
templateArgType = vt2->containerTypeToken->type();
if (Token::simpleMatch(autoToken->next(), "&"))
@@ -6921,19 +6911,19 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
if (vt1 && vt1->containerTypeToken && parent->str() == "[") {
ValueType vtParent;
- if (parsedecl(vt1->containerTypeToken, &vtParent, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(vt1->containerTypeToken, &vtParent, mDefaultSignedness, mSettings)) {
setValueType(parent, vtParent);
return;
}
}
- if (mIsCpp && vt2 && Token::simpleMatch(parent->previous(), "decltype (")) {
+ if (parent->isCpp() && vt2 && Token::simpleMatch(parent->previous(), "decltype (")) {
setValueType(parent, *vt2);
return;
}
// c++17 auto type deduction of braced init list
- if (mIsCpp && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) {
+ if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) {
Token *autoTok = parent->tokAt(-2);
setValueType(autoTok, *vt2);
setAutoTokenProperties(autoTok);
@@ -7100,7 +7090,6 @@ static const Token* parsedecl(const Token* type,
ValueType* const valuetype,
ValueType::Sign defaultSignedness,
const Settings& settings,
- bool isCpp,
SourceLocation loc)
{
if (settings.debugnormal || settings.debugwarnings)
@@ -7162,7 +7151,7 @@ static const Token* parsedecl(const Token* type,
if (valuetype->type == ValueType::Type::UNKNOWN_TYPE &&
type->type() && type->type()->isTypeAlias() && type->type()->typeStart &&
type->type()->typeStart->str() != type->str() && type->type()->typeStart != previousType)
- parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp);
+ parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings);
else if (Token::Match(type, "const|constexpr"))
valuetype->constness |= (1 << (valuetype->pointer - pointer0));
else if (Token::simpleMatch(type, "volatile"))
@@ -7194,7 +7183,7 @@ static const Token* parsedecl(const Token* type,
if (valuetype->typeScope)
valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD;
}
- } else if (const Library::Container* container = (isCpp ? settings.library.detectContainerOrIterator(type, &isIterator) : nullptr)) {
+ } else if (const Library::Container* container = (type->isCpp() ? settings.library.detectContainerOrIterator(type, &isIterator) : nullptr)) {
if (isIterator)
valuetype->type = ValueType::Type::ITERATOR;
else
@@ -7216,7 +7205,7 @@ static const Token* parsedecl(const Token* type,
// we are past the end of the type
type = type->previous();
continue;
- } else if (const Library::SmartPointer* smartPointer = (isCpp ? settings.library.detectSmartPointer(type) : nullptr)) {
+ } else if (const Library::SmartPointer* smartPointer = (type->isCpp() ? settings.library.detectSmartPointer(type) : nullptr)) {
const Token* argTok = Token::findsimplematch(type, "<");
if (!argTok)
break;
@@ -7423,11 +7412,11 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
setValueType(tok, ValueType(sign, type, 0U));
}
} else if (tok->isComparisonOp() || tok->tokType() == Token::eLogicalOp) {
- if (mIsCpp && tok->isComparisonOp() && (getClassScope(tok->astOperand1()) || getClassScope(tok->astOperand2()))) {
+ if (tok->isCpp() && tok->isComparisonOp() && (getClassScope(tok->astOperand1()) || getClassScope(tok->astOperand2()))) {
const Function *function = getOperatorFunction(tok);
if (function) {
ValueType vt;
- parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings, mIsCpp);
+ parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings);
setValueType(tok, vt);
continue;
}
@@ -7441,7 +7430,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
nonneg int const volatileness = 0U;
ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness, volatileness);
- if (mIsCpp && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) {
+ if (tok->isCpp() && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) {
valuetype.originalTypeName = "char8_t";
valuetype.fromLibraryType(valuetype.originalTypeName, mSettings);
} else if (tok->isUtf16()) {
@@ -7453,7 +7442,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
} else if (tok->isLong()) {
valuetype.originalTypeName = "wchar_t";
valuetype.type = ValueType::Type::WCHAR_T;
- } else if ((tok->tokType() == Token::eChar) && ((tok->isCChar() && !mIsCpp) || (tok->isCMultiChar()))) {
+ } else if ((tok->tokType() == Token::eChar) && ((!tok->isCpp() && tok->isCChar()) || (tok->isCMultiChar()))) {
valuetype.type = ValueType::Type::INT;
valuetype.sign = ValueType::Sign::SIGNED;
}
@@ -7463,21 +7452,21 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
// cast
if (tok->isCast() && !tok->astOperand2() && Token::Match(tok, "( %name%")) {
ValueType valuetype;
- if (Token::simpleMatch(parsedecl(tok->next(), &valuetype, mDefaultSignedness, mSettings, mIsCpp), ")"))
+ if (Token::simpleMatch(parsedecl(tok->next(), &valuetype, mDefaultSignedness, mSettings), ")"))
setValueType(tok, valuetype);
}
// C++ cast
else if (tok->astOperand2() && Token::Match(tok->astOperand1(), "static_cast|const_cast|dynamic_cast|reinterpret_cast < %name%") && tok->astOperand1()->linkAt(1)) {
ValueType valuetype;
- if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype, mDefaultSignedness, mSettings, mIsCpp), ">"))
+ if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype, mDefaultSignedness, mSettings), ">"))
setValueType(tok, valuetype);
}
// Construct smart pointer
- else if (mIsCpp && mSettings.library.isSmartPointer(start)) {
+ else if (start && start->isCpp() && mSettings.library.isSmartPointer(start)) {
ValueType valuetype;
- if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings)) {
setValueType(tok, valuetype);
setValueType(tok->astOperand1(), valuetype);
}
@@ -7487,7 +7476,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
// function or lambda
else if (const Function* f = getFunction(tok->previous())) {
ValueType valuetype;
- if (parsedecl(f->retDef, &valuetype, mDefaultSignedness, mSettings, mIsCpp))
+ if (parsedecl(f->retDef, &valuetype, mDefaultSignedness, mSettings))
setValueType(tok, valuetype);
}
@@ -7501,7 +7490,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
if (Token::Match(tok, "( %type% %type%| *| *| )")) {
ValueType vt;
- if (parsedecl(tok->next(), &vt, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(tok->next(), &vt, mDefaultSignedness, mSettings)) {
setValueType(tok->next(), vt);
}
}
@@ -7543,21 +7532,21 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
// Aggregate constructor
if (Token::Match(tok->previous(), "%name%")) {
ValueType valuetype;
- if (parsedecl(tok->previous(), &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(tok->previous(), &valuetype, mDefaultSignedness, mSettings)) {
if (valuetype.typeScope) {
setValueType(tok, valuetype);
continue;
}
}
}
- if (mIsCpp && tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) {
+ if (tok->isCpp() && tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) {
const Token *typeStartToken = tok->astOperand1();
while (typeStartToken && typeStartToken->str() == "::")
typeStartToken = typeStartToken->astOperand1();
if (mSettings.library.detectContainerOrIterator(typeStartToken) ||
mSettings.library.detectSmartPointer(typeStartToken)) {
ValueType vt;
- if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings)) {
setValueType(tok, vt);
continue;
}
@@ -7567,7 +7556,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
if ((e == "std::make_shared" || e == "std::make_unique") && Token::Match(tok->astOperand1(), ":: %name% < %name%")) {
ValueType vt;
- parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mSettings, mIsCpp);
+ parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mSettings);
if (vt.typeScope) {
vt.smartPointerType = vt.typeScope->definedType;
vt.typeScope = nullptr;
@@ -7596,7 +7585,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
std::istringstream istr(typestr+";");
tokenList.createTokens(istr, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
tokenList.simplifyStdType();
- if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings)) {
valuetype.originalTypeName = typestr;
setValueType(tok, valuetype);
}
@@ -7688,7 +7677,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
ValueType vt;
tokenList.simplifyPlatformTypes();
tokenList.simplifyStdType();
- if (parsedecl(tokenList.front(), &vt, mDefaultSignedness, mSettings, mIsCpp)) {
+ if (parsedecl(tokenList.front(), &vt, mDefaultSignedness, mSettings)) {
vt.originalTypeName = typestr;
setValueType(tok, vt);
}
@@ -7761,7 +7750,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
fscope = fscope->nestedIn;
if (fscope && fscope->function && fscope->function->retDef) {
ValueType vt;
- parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings, mIsCpp);
+ parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings);
setValueType(tok, vt);
}
} else if (tok->isKeyword() && tok->str() == "this" && tok->scope()->isExecutable()) {
@@ -7803,7 +7792,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
ValueType ValueType::parseDecl(const Token *type, const Settings &settings)
{
ValueType vt;
- parsedecl(type, &vt, settings.platform.defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings, type->isCpp());
+ parsedecl(type, &vt, settings.platform.defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings);
return vt;
}
diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h
index 9d378298f7e..ffa0777ecf5 100644
--- a/lib/symboldatabase.h
+++ b/lib/symboldatabase.h
@@ -1176,7 +1176,7 @@ class CPPCHECKLIB Scope {
*/
const Variable *getVariable(const std::string &varname) const;
- const Token * addEnum(const Token * tok, bool isCpp);
+ const Token * addEnum(const Token * tok);
const Scope *findRecordInBase(const std::string &name) const;
@@ -1387,8 +1387,6 @@ class CPPCHECKLIB SymbolDatabase {
void printVariable(const Variable *var, const char *indent) const;
void printXml(std::ostream &out) const;
- bool isCPP() const;
-
/*
* @brief Do a sanity check
*/
@@ -1452,8 +1450,8 @@ class CPPCHECKLIB SymbolDatabase {
void fixVarId(VarIdMap & varIds, const Token * vartok, Token * membertok, const Variable * membervar);
- /** Whether iName is a keyword as defined in http://en.cppreference.com/w/c/keyword and http://en.cppreference.com/w/cpp/keyword*/
- bool isReservedName(const std::string& iName) const;
+ /** Whether the token is a keyword as defined in http://en.cppreference.com/w/c/keyword and http://en.cppreference.com/w/cpp/keyword*/
+ static bool isReservedName(const Token* tok);
const Enumerator * findEnumerator(const Token * tok, std::set& tokensThatAreNotEnumeratorValues) const;
@@ -1477,7 +1475,6 @@ class CPPCHECKLIB SymbolDatabase {
/** list for missing types */
std::list mBlankTypes;
- bool mIsCpp;
ValueType::Sign mDefaultSignedness;
};
diff --git a/lib/token.cpp b/lib/token.cpp
index 0a2024aee76..c169577106b 100644
--- a/lib/token.cpp
+++ b/lib/token.cpp
@@ -491,7 +491,7 @@ int multiComparePercent(const Token *tok, const char*& haystack, nonneg int vari
// Type (%type%)
{
haystack += 5;
- if (tok->isName() && tok->varId() == 0 && (tok->str() != "delete" || !tok->isKeyword())) // HACK: this is legacy behaviour, it should return false for all keywords, except types
+ if (tok->isName() && tok->varId() == 0)
return 1;
}
break;
diff --git a/lib/token.h b/lib/token.h
index 0a3f9ecc148..4c5ceaba111 100644
--- a/lib/token.h
+++ b/lib/token.h
@@ -265,18 +265,18 @@ class CPPCHECKLIB Token {
* - "%char%" Any token enclosed in '-character.
* - "%comp%" Any token such that isComparisonOp() returns true.
* - "%cop%" Any token such that isConstOp() returns true.
- * - "%name%" any token which is a name, variable or type e.g. "hello" or "int"
+ * - "%name%" any token which is a name, variable or type e.g. "hello" or "int". Also matches keywords.
* - "%num%" Any numeric token, e.g. "23"
* - "%op%" Any token such that isOp() returns true.
* - "%or%" A bitwise-or operator '|'
* - "%oror%" A logical-or operator '||'
- * - "%type%" Anything that can be a variable type, e.g. "int", but not "delete".
+ * - "%type%" Anything that can be a variable type, e.g. "int". Also matches keywords.
* - "%str%" Any token starting with "-character (C-string).
* - "%var%" Match with token with varId > 0
* - "%varid%" Match with parameter varid
* - "[abc]" Any of the characters 'a' or 'b' or 'c'
* - "int|void|char" Any of the strings, int, void or char
- * - "int|void|char|" Any of the strings, int, void or char or empty string
+ * - "int|void|char|" Any of the strings, int, void or char or no token
* - "!!else" No tokens or any token that is not "else".
* - "someRandomText" If token contains "someRandomText".
*
diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp
index dfd9ed8bc79..a2dba01c5ea 100644
--- a/lib/tokenize.cpp
+++ b/lib/tokenize.cpp
@@ -313,7 +313,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
return false;
} else if (tok->previous()->str() == "union") {
return tok->next()->str() != ";";
- } else if (isCPP() && tok->previous()->str() == "class") {
+ } else if (tok->isCpp() && tok->previous()->str() == "class") {
return tok->next()->str() != ";";
}
if (tok)
@@ -1697,7 +1697,7 @@ void Tokenizer::simplifyTypedefCpp()
}
// check for member functions
- else if (isCPP() && tok2->str() == "(" && isFunctionHead(tok2, "{:")) {
+ else if (tok2->isCpp() && tok2->str() == "(" && isFunctionHead(tok2, "{:")) {
const Token *func = tok2->previous();
/** @todo add support for multi-token operators */
@@ -1724,7 +1724,7 @@ void Tokenizer::simplifyTypedefCpp()
// check for entering a new scope
else if (tok2->str() == "{") {
// check for entering a new namespace
- if (isCPP()) {
+ if (tok2->isCpp()) {
if (tok2->strAt(-2) == "namespace") {
if (classLevel < spaceInfo.size() &&
spaceInfo[classLevel].isNamespace &&
@@ -1753,7 +1753,7 @@ void Tokenizer::simplifyTypedefCpp()
// check for operator typedef
/** @todo add support for multi-token operators */
- else if (isCPP() &&
+ else if (tok2->isCpp() &&
tok2->str() == "operator" &&
tok2->next() &&
tok2->next()->str() == typeName->str() &&
@@ -1940,7 +1940,7 @@ void Tokenizer::simplifyTypedefCpp()
// start substituting at the typedef name by replacing it with the type
Token* replStart = tok2; // track first replaced token
- for (Token* tok3 = typeStart; tok3->str() != ";"; tok3 = tok3->next())
+ for (Token* tok3 = typeStart; tok3 && (tok3->str() != ";"); tok3 = tok3->next())
tok3->isSimplifiedTypedef(true);
if (isPointerTypeCall) {
tok2->deleteThis();
@@ -2844,6 +2844,9 @@ bool Tokenizer::simplifyUsing()
for (Token* tok = list.front(); tok; tok = tok->next()) {
if (!Token::Match(tok, "using ::| %name% ::"))
continue;
+ const Token* ns = tok->tokAt(tok->strAt(1) == "::" ? 2 : 1);
+ if (ns->isKeyword())
+ continue;
Token* end = tok->tokAt(3);
while (end && !Token::Match(end, "[;,]")) {
if (end->str() == "<" && end->link()) // skip template args
@@ -4528,7 +4531,7 @@ void Tokenizer::setVarIdPass1()
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->isOp())
continue;
- if (isCPP() && Token::simpleMatch(tok, "template <")) {
+ if (tok->isCpp() && Token::simpleMatch(tok, "template <")) {
Token* closingBracket = tok->next()->findClosingBracket();
if (closingBracket)
tok = closingBracket;
@@ -4722,7 +4725,7 @@ void Tokenizer::setVarIdPass1()
;
else if (Token::Match(prev2, "%type% ( !!)") && Token::simpleMatch(tok2->link(), ") ;")) {
// In C++ , a variable can't be called operator+ or something like that.
- if (isCPP() &&
+ if (prev2->isCpp() &&
prev2->isOperatorKeyword())
continue;
@@ -4804,7 +4807,7 @@ void Tokenizer::setVarIdPass1()
if (tok->isName() && !tok->isKeyword() && !tok->isStandardType()) {
// don't set variable id after a struct|enum|union
- if (Token::Match(tok->previous(), "struct|enum|union") || (isCPP() && tok->strAt(-1) == "class"))
+ if (Token::Match(tok->previous(), "struct|enum|union") || (tok->isCpp() && tok->strAt(-1) == "class"))
continue;
bool globalNamespace = false;
@@ -4821,7 +4824,7 @@ void Tokenizer::setVarIdPass1()
}
// function declaration inside executable scope? Function declaration is of form: type name "(" args ")"
- if (scopeStack.top().isExecutable && Token::Match(tok, "%name% [,)]")) {
+ if (scopeStack.top().isExecutable && Token::Match(tok, "%name% [,)[]")) {
bool par = false;
const Token *start, *end;
@@ -4841,7 +4844,7 @@ void Tokenizer::setVarIdPass1()
}
// search end of function declaration
- for (end = tok->next(); Token::Match(end, "%name%|*|&|,"); end = end->next()) {}
+ for (end = tok->next(); Token::Match(end, "%name%|*|&|,|[|]|%num%"); end = end->next()) {}
// there are tokens which can't appear at the begin of a function declaration such as "return"
const bool isNotstartKeyword = start->next() && notstart.find(start->next()->str()) != notstart.end();
@@ -5756,10 +5759,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// Remove redundant parentheses
simplifyRedundantParentheses();
- if (isCPP())
+ if (isCPP()) {
simplifyTypeIntrinsics();
- if (!isC()) {
// Handle templates..
if (mTimerResults) {
Timer t("Tokenizer::simplifyTokens1::simplifyTokenList1::simplifyTemplates", mSettings.showtime, mTimerResults);
@@ -6153,7 +6155,7 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
// functions and types to keep
std::set keep;
for (const Token *tok = list.front(); tok; tok = tok->next()) {
- if (isCPP() && Token::simpleMatch(tok, "template <")) {
+ if (tok->isCpp() && Token::simpleMatch(tok, "template <")) {
const Token *closingBracket = tok->next()->findClosingBracket();
if (Token::Match(closingBracket, "> class|struct %name% {"))
tok = closingBracket->linkAt(3);
@@ -6658,7 +6660,10 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
}
if (!tokEnd || tokEnd->str() != ";") {
// No trailing ;
- return tok;
+ if (tokStatement->isUpperCaseName())
+ unknownMacroError(tokStatement);
+ else
+ syntaxError(tokStatement);
}
}
@@ -6884,7 +6889,7 @@ void Tokenizer::simplifyFunctionPointers()
Token::Match(tok, "static_cast < %type% %type%| *| *| ( * ) (")) {
Token *tok1 = tok;
- if (isCPP() && tok1->str() == "static_cast")
+ if (tok1->isCpp() && tok1->str() == "static_cast")
tok1 = tok1->next();
tok1 = tok1->next();
@@ -6997,7 +7002,7 @@ void Tokenizer::simplifyVarDecl(const bool only_k_r_fpar)
void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, const bool only_k_r_fpar)
{
- const bool isCPP11 = mSettings.standards.cpp >= Standards::CPP11;
+ const bool isCPP11 = isCPP() && (mSettings.standards.cpp >= Standards::CPP11);
// Split up variable declarations..
// "int a=4;" => "int a; a=4;"
@@ -7085,7 +7090,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
continue;
if (isCPP11 && type0->str() == "using")
continue;
- if (isCPP() && type0->str() == "namespace")
+ if (type0->isCpp() && Token::Match(type0, "namespace|delete"))
continue;
bool isconst = false;
@@ -7744,7 +7749,7 @@ bool Tokenizer::simplifyRedundantParentheses()
if (tok->str() != "(")
continue;
- if (isCPP() && Token::simpleMatch(tok->previous(), "} (")) {
+ if (tok->isCpp() && Token::simpleMatch(tok->previous(), "} (")) {
const Token* plp = tok->previous()->link()->previous();
if (Token::Match(plp, "%name%|>|] {") || (Token::simpleMatch(plp, ")") && Token::simpleMatch(plp->link()->previous(), "]")))
continue;
@@ -8442,7 +8447,7 @@ void Tokenizer::findGarbageCode() const
if (!Token::Match(tok->next(), "( !!)"))
syntaxError(tok);
if (tok->str() != "for") {
- if (isGarbageExpr(tok->next(), tok->linkAt(1), mSettings.standards.cpp>=Standards::cppstd_t::CPP17))
+ if (isGarbageExpr(tok->next(), tok->linkAt(1), isCPP() && (mSettings.standards.cpp>=Standards::cppstd_t::CPP17)))
syntaxError(tok);
}
}
@@ -8535,13 +8540,15 @@ void Tokenizer::findGarbageCode() const
if (!Token::simpleMatch(tok, "for (")) // find for loops
continue;
// count number of semicolons
- int semicolons = 0;
+ int semicolons = 0, colons = 0;
const Token* const startTok = tok;
tok = tok->next()->link()->previous(); // find ")" of the for-loop
// walk backwards until we find the beginning (startTok) of the for() again
for (; tok != startTok; tok = tok->previous()) {
if (tok->str() == ";") { // do the counting
semicolons++;
+ } else if (tok->str() == ":") {
+ colons++;
} else if (tok->str() == ")") { // skip pairs of ( )
tok = tok->link();
}
@@ -8551,6 +8558,8 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (semicolons == 1 && !(isCPP() && mSettings.standards.cpp >= Standards::CPP20))
syntaxError(tok);
+ if (semicolons == 0 && colons == 0)
+ syntaxError(tok);
}
// Operators without operands..
@@ -9131,7 +9140,7 @@ void Tokenizer::simplifyCppcheckAttribute()
void Tokenizer::simplifyCPPAttribute()
{
- if (mSettings.standards.cpp < Standards::CPP11 || isC())
+ if (!isCPP() || mSettings.standards.cpp < Standards::CPP11)
return;
for (Token *tok = list.front(); tok;) {
@@ -10534,6 +10543,8 @@ void Tokenizer::simplifyNamespaceAliases()
int endScope = scope;
Token * tokLast = tokNameEnd->next();
+ if (!tokLast)
+ return;
Token * tokNext = tokLast->next();
Token * tok2 = tokNext;
diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp
index 7039c72ef7e..d8048af2ee3 100644
--- a/lib/tokenlist.cpp
+++ b/lib/tokenlist.cpp
@@ -1424,7 +1424,7 @@ const Token* findLambdaEndTokenWithoutAST(const Token* tok) {
return tok->link()->next();
}
-static Token * createAstAtToken(Token *tok, bool cpp);
+static Token * createAstAtToken(Token *tok);
// Compile inner expressions inside inner ({..}) and lambda bodies
static void createAstAtTokenInner(Token * const tok1, const Token *endToken, bool cpp)
@@ -1445,7 +1445,7 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
}
if (!hasAst) {
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
- tok = createAstAtToken(tok, cpp);
+ tok = createAstAtToken(tok);
}
} else if (cpp && tok->str() == "[") {
if (isLambdaCaptureList(tok)) {
@@ -1455,7 +1455,7 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
const Token * const endToken2 = tok->link();
tok = tok->next();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
- tok = createAstAtToken(tok, cpp);
+ tok = createAstAtToken(tok);
}
}
else if (Token::simpleMatch(tok, "( * ) [")) {
@@ -1497,8 +1497,9 @@ static Token * findAstTop(Token *tok1, const Token *tok2)
return nullptr;
}
-static Token * createAstAtToken(Token *tok, bool cpp)
+static Token * createAstAtToken(Token *tok)
{
+ const bool cpp = tok->isCpp();
// skip function pointer declaration
if (Token::Match(tok, "%type% %type%") && !Token::Match(tok, "return|throw|new|delete")) {
Token* tok2 = tok->tokAt(2);
@@ -1581,7 +1582,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
AST_state state1(cpp);
compileExpression(tok2, state1);
if (Token::Match(init1, "( !!{")) {
- for (Token *tok3 = init1; tok3 != tok3->link(); tok3 = tok3->next()) {
+ for (Token *tok3 = init1; tok3 && tok3 != tok3->link(); tok3 = tok3->next()) {
if (tok3->astParent()) {
while (tok3->astParent())
tok3 = tok3->astParent();
@@ -1754,7 +1755,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
void TokenList::createAst() const
{
for (Token *tok = mTokensFrontBack.front; tok; tok = tok ? tok->next() : nullptr) {
- tok = createAstAtToken(tok, isCPP());
+ tok = createAstAtToken(tok);
}
}
diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp
index 2c734df9925..5a3833419b0 100644
--- a/lib/valueflow.cpp
+++ b/lib/valueflow.cpp
@@ -1210,7 +1210,7 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings)
static bool getMinMaxValues(const ValueType* vt, const Platform& platform, MathLib::bigint& minValue, MathLib::bigint& maxValue);
// Handle various constants..
-static Token * valueFlowSetConstantValue(Token *tok, const Settings &settings, bool cpp)
+static Token * valueFlowSetConstantValue(Token *tok, const Settings &settings)
{
if ((tok->isNumber() && MathLib::isInt(tok->str())) || (tok->tokType() == Token::eChar)) {
try {
@@ -1240,7 +1240,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings &settings, b
if (!tok->isTemplateArg())
value.setKnown();
setTokenValue(tok, std::move(value), settings);
- } else if (tok->str() == "NULL" || (cpp && tok->str() == "nullptr")) {
+ } else if (tok->str() == "NULL" || (tok->isCpp() && tok->str() == "nullptr")) {
ValueFlow::Value value(0);
if (!tok->isTemplateArg())
value.setKnown();
@@ -1359,7 +1359,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings &settings, b
}
} else if (tok2->tokType() == Token::eChar) {
nonneg int sz = 0;
- if (cpp && settings.standards.cpp >= Standards::CPP20 && tok2->isUtf8())
+ if (tok2->isCpp() && settings.standards.cpp >= Standards::CPP20 && tok2->isUtf8())
sz = 1;
else if (tok2->isUtf16())
sz = 2;
@@ -1367,7 +1367,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings &settings, b
sz = 4;
else if (tok2->isLong())
sz = settings.platform.sizeof_wchar_t;
- else if ((tok2->isCChar() && !cpp) || (tok2->isCMultiChar()))
+ else if ((!tok2->isCpp() && tok2->isCChar()) || (tok2->isCMultiChar()))
sz = settings.platform.sizeof_int;
else
sz = 1;
@@ -1427,7 +1427,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings &settings, b
static void valueFlowNumber(TokenList &tokenlist, const Settings& settings)
{
for (Token *tok = tokenlist.front(); tok;) {
- tok = valueFlowSetConstantValue(tok, settings, tokenlist.isCPP());
+ tok = valueFlowSetConstantValue(tok, settings);
}
if (tokenlist.isCPP()) {
@@ -1738,7 +1738,7 @@ static void valueFlowSameExpressions(TokenList &tokenlist, const Settings& setti
if (!val.isKnown())
continue;
- if (isSameExpression(tokenlist.isCPP(), false, tok->astOperand1(), tok->astOperand2(), settings.library, true, true, &val.errorPath)) {
+ if (isSameExpression(false, tok->astOperand1(), tok->astOperand2(), settings.library, true, true, &val.errorPath)) {
setTokenValue(tok, std::move(val), settings);
}
}
@@ -2087,9 +2087,9 @@ static void valueFlowGlobalStaticVar(TokenList &tokenList, const Settings &setti
else if (tok->astParent()->isAssignmentOp()) {
if (tok == tok->astParent()->astOperand1())
vars.erase(tok->variable());
- else if (tokenList.isCPP() && Token::Match(tok->astParent()->tokAt(-2), "& %name% ="))
+ else if (tok->isCpp() && Token::Match(tok->astParent()->tokAt(-2), "& %name% ="))
vars.erase(tok->variable());
- } else if (isLikelyStreamRead(tokenList.isCPP(), tok->astParent())) {
+ } else if (isLikelyStreamRead(tok->astParent())) {
vars.erase(tok->variable());
} else if (Token::Match(tok->astParent(), "[(,]"))
vars.erase(tok->variable());
@@ -2417,7 +2417,7 @@ static bool bifurcateVariableChanged(const Variable* var,
bool result = false;
const Token* tok = start;
while ((tok = findVariableChanged(
- tok->next(), end, var->isPointer(), var->declarationId(), var->isGlobal(), &settings, true))) {
+ tok->next(), end, var->isPointer(), var->declarationId(), var->isGlobal(), &settings))) {
if (Token::Match(tok->astParent(), "%assign%")) {
if (!bifurcate(tok->astParent()->astOperand2(), varids, settings, depth - 1))
return true;
@@ -2572,7 +2572,7 @@ struct ValueFlowAnalyzer : Analyzer {
return result;
}
if (Token::Match(tok, "%cop%")) {
- if (isLikelyStream(isCPP(), tok->astOperand1())) {
+ if (isLikelyStream(tok->astOperand1())) {
result.dependent = false;
return result;
}
@@ -2643,7 +2643,7 @@ struct ValueFlowAnalyzer : Analyzer {
return read | Action::Invalid;
if (inconclusive)
return read | Action::Inconclusive;
- if (isVariableChanged(tok, getIndirect(tok), &getSettings(), isCPP())) {
+ if (isVariableChanged(tok, getIndirect(tok), &getSettings())) {
if (Token::Match(tok->astParent(), "*|[|.|++|--"))
return read | Action::Invalid;
// Check if its assigned to the same value
@@ -2672,13 +2672,13 @@ struct ValueFlowAnalyzer : Analyzer {
}
}
for (int i = 0; i <= indirect; ++i)
- if (isVariableChanged(tok, i, &getSettings(), isCPP()))
+ if (isVariableChanged(tok, i, &getSettings()))
return Action::Invalid;
return Action::None;
}
virtual Action isThisModified(const Token* tok) const {
- if (isThisChanged(tok, 0, &getSettings(), isCPP()))
+ if (isThisChanged(tok, 0, &getSettings()))
return Action::Invalid;
return Action::None;
}
@@ -3237,7 +3237,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
setupExprVarIds(value.tokvalue);
}
uniqueExprId =
- expr->isUniqueExprId() && (Token::Match(expr, "%cop%") || !isVariableChanged(expr, 0, &s, t.isCPP()));
+ expr->isUniqueExprId() && (Token::Match(expr, "%cop%") || !isVariableChanged(expr, 0, &s));
}
static bool nonLocal(const Variable* var, bool deref) {
@@ -3275,7 +3275,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
if (!Token::simpleMatch(tok->previous(), ".")) {
const Variable* var = tok->variable();
if (var && var->isReference() && var->isLocal() && Token::Match(var->nameToken(), "%var% [=(]") &&
- !isGlobalData(var->nameToken()->next()->astOperand2(), isCPP()))
+ !isGlobalData(var->nameToken()->next()->astOperand2()))
return ChildrenToVisit::none;
const bool deref = tok->astParent() &&
(tok->astParent()->isUnaryOp("*") ||
@@ -3337,7 +3337,7 @@ struct SameExpressionAnalyzer : ExpressionAnalyzer {
bool match(const Token* tok) const override
{
- return isSameExpression(isCPP(), true, expr, tok, getSettings().library, true, true);
+ return isSameExpression(true, expr, tok, getSettings().library, true, true);
}
};
@@ -3353,7 +3353,7 @@ struct OppositeExpressionAnalyzer : ExpressionAnalyzer {
}
bool match(const Token* tok) const override {
- return isOppositeCond(isNot, isCPP(), expr, tok, getSettings().library, true, true);
+ return isOppositeCond(isNot, expr, tok, getSettings().library, true, true);
}
};
@@ -3561,7 +3561,7 @@ static std::vector getLifetimeTokens(const Token* tok,
if (Token::Match(varDeclEndToken, "=|{")) {
errorPath.emplace_back(varDeclEndToken, "Assigned to reference.");
const Token *vartok = varDeclEndToken->astOperand2();
- const bool temporary = isTemporary(true, vartok, nullptr, true);
+ const bool temporary = isTemporary(vartok, nullptr, true);
const bool nonlocal = var->isStatic() || var->isGlobal();
if (vartok == tok || (nonlocal && temporary) ||
(!escape && (var->isConst() || var->isRValueReference()) && temporary))
@@ -4012,7 +4012,7 @@ static void valueFlowForwardLifetime(Token * tok, TokenList &tokenlist, ErrorLog
// TODO: handle `[`
if (Token::simpleMatch(parent->astOperand1(), ".")) {
const Token* parentLifetime =
- getParentLifetime(tokenlist.isCPP(), parent->astOperand1()->astOperand2(), &settings.library);
+ getParentLifetime(parent->astOperand1()->astOperand2(), &settings.library);
if (parentLifetime && parentLifetime->exprId() > 0) {
valueFlowForward(nextExpression, endOfVarScope, parentLifetime, std::move(values), tokenlist, errorLogger, settings);
}
@@ -4527,7 +4527,7 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList &tokenlist, ErrorLog
if (returnTok == tok)
continue;
const Variable *returnVar = ValueFlow::getLifetimeVariable(returnTok);
- if (returnVar && returnVar->isArgument() && (returnVar->isConst() || !isVariableChanged(returnVar, &settings, tokenlist.isCPP()))) {
+ if (returnVar && returnVar->isArgument() && (returnVar->isConst() || !isVariableChanged(returnVar, &settings))) {
LifetimeStore ls = LifetimeStore::fromFunctionArg(f, tok, returnVar, tokenlist, settings, errorLogger);
ls.inconclusive = inconclusive;
ls.forward = false;
@@ -5356,7 +5356,7 @@ static void valueFlowConditionExpressions(const TokenList &tokenlist, const Symb
continue;
if (condTok->hasKnownIntValue())
continue;
- if (!isConstExpression(condTok, settings.library, tokenlist.isCPP()))
+ if (!isConstExpression(condTok, settings.library))
continue;
const bool is1 = (condTok->isComparisonOp() || condTok->tokType() == Token::eLogicalOp || astIsBool(condTok));
@@ -5483,7 +5483,7 @@ static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase&
continue;
if (tok->astOperand2()->exprId() == 0)
continue;
- if (!isConstExpression(tok->astOperand2(), settings.library, tokenlist.isCPP()))
+ if (!isConstExpression(tok->astOperand2(), settings.library))
continue;
if (tok->astOperand1()->valueType() && tok->astOperand2()->valueType()) {
if (isTruncated(
@@ -5782,7 +5782,7 @@ static ValueFlow::Value::Bound findVarBound(const Variable* var,
ValueFlow::Value::Bound result = ValueFlow::Value::Bound::Point;
const Token* next = start;
while ((next = findExpressionChangedSkipDeadCode(
- var->nameToken(), next->next(), end, settings, true, &evaluateKnownValues))) {
+ var->nameToken(), next->next(), end, settings, &evaluateKnownValues))) {
ValueFlow::Value::Bound b = ValueFlow::Value::Bound::Point;
if (next->varId() != var->declarationId())
return ValueFlow::Value::Bound::Point;
@@ -6322,8 +6322,7 @@ struct ConditionHandler {
valueFlowReverse(start, endToken, exprTok, values, tokenlist, errorLogger, settings, loc);
}
- void traverseCondition(const TokenList& tokenlist,
- const SymbolDatabase& symboldatabase,
+ void traverseCondition(const SymbolDatabase& symboldatabase,
const Settings& settings,
const std::set& skippedFunctions,
const std::function& f) const
@@ -6352,7 +6351,7 @@ struct ConditionHandler {
continue;
if (cond.true_values.empty() || cond.false_values.empty())
continue;
- if (!isConstExpression(cond.vartok, settings.library, tokenlist.isCPP()))
+ if (!isConstExpression(cond.vartok, settings.library))
continue;
f(cond, tok, scope);
}
@@ -6365,7 +6364,7 @@ struct ConditionHandler {
ErrorLogger* errorLogger,
const Settings& settings,
const std::set& skippedFunctions) const {
- traverseCondition(tokenlist, symboldatabase, settings, skippedFunctions, [&](const Condition& cond, Token* tok, const Scope*) {
+ traverseCondition(symboldatabase, settings, skippedFunctions, [&](const Condition& cond, Token* tok, const Scope*) {
if (cond.vartok->exprId() == 0)
return;
@@ -6423,7 +6422,7 @@ struct ConditionHandler {
if (Token::simpleMatch(top->previous(), "for (")) {
if (top->astOperand2() && top->astOperand2()->astOperand2() &&
findExpressionChanged(
- cond.vartok, top->astOperand2()->astOperand2(), top->link(), &settings, tokenlist.isCPP())) {
+ cond.vartok, top->astOperand2()->astOperand2(), top->link(), &settings)) {
if (settings.debugwarnings)
bailout(tokenlist,
errorLogger,
@@ -6438,7 +6437,7 @@ struct ConditionHandler {
const Token* const block = top->link()->next();
const Token* const end = block->link();
- if (findExpressionChanged(cond.vartok, start, end, &settings, tokenlist.isCPP())) {
+ if (findExpressionChanged(cond.vartok, start, end, &settings)) {
// If its reassigned in loop then analyze from the end
if (!Token::Match(tok, "%assign%|++|--") &&
findExpression(cond.vartok->exprId(), start, end, [&](const Token* tok2) {
@@ -6513,7 +6512,7 @@ struct ConditionHandler {
ErrorLogger* errorLogger,
const Settings& settings,
const std::set& skippedFunctions) const {
- traverseCondition(tokenlist, symboldatabase, settings, skippedFunctions, [&](const Condition& cond, Token* condTok, const Scope* scope) {
+ traverseCondition(symboldatabase, settings, skippedFunctions, [&](const Condition& cond, Token* condTok, const Scope* scope) {
Token* top = condTok->astTop();
const MathLib::bigint path = cond.getPath();
@@ -6664,8 +6663,7 @@ struct ConditionHandler {
startBlock->link(),
cond.vartok->varId(),
cond.vartok->variable()->isGlobal(),
- &settings,
- tokenlist.isCPP()))
+ &settings))
return;
// Check if condition in for loop is always false
const Token* initTok = getInitTok(top);
@@ -7039,7 +7037,7 @@ struct SymbolicConditionHandler : SimpleConditionHandler {
return {};
if (!tok->astOperand2() || tok->astOperand2()->hasKnownIntValue() || tok->astOperand2()->isLiteral())
return {};
- if (!isConstExpression(tok, settings.library, true))
+ if (!isConstExpression(tok, settings.library))
return {};
std::vector result;
@@ -7147,7 +7145,7 @@ static void valueFlowForLoopSimplify(Token* const bodyStart,
const Token * const bodyEnd = bodyStart->link();
// Is variable modified inside for loop
- if (isVariableChanged(bodyStart, bodyEnd, expr->varId(), globalvar, &settings, tokenlist.isCPP()))
+ if (isVariableChanged(bodyStart, bodyEnd, expr->varId(), globalvar, &settings))
return;
for (Token *tok2 = bodyStart->next(); tok2 != bodyEnd; tok2 = tok2->next()) {
@@ -7934,7 +7932,7 @@ static void valueFlowFunctionReturn(TokenList &tokenlist, ErrorLogger *errorLogg
}
}
-static bool needsInitialization(const Variable* var, bool cpp)
+static bool needsInitialization(const Variable* var)
{
if (!var)
return false;
@@ -7944,7 +7942,7 @@ static bool needsInitialization(const Variable* var, bool cpp)
return true;
if (var->type() && var->type()->isUnionType())
return false;
- if (!cpp)
+ if (!var->nameToken()->isCpp())
return true;
if (var->type() && var->type()->needInitialization == Type::NeedInitialization::True)
return true;
@@ -8057,7 +8055,7 @@ static void valueFlowUninit(TokenList& tokenlist, ErrorLogger* const errorLogger
continue;
if (var->nameToken() != tok || var->isInit())
continue;
- if (!needsInitialization(var, tokenlist.isCPP()))
+ if (!needsInitialization(var))
continue;
if (!var->isLocal() || var->isStatic() || var->isExtern() || var->isReference() || var->isThrow())
continue;
@@ -8083,7 +8081,7 @@ static void valueFlowUninit(TokenList& tokenlist, ErrorLogger* const errorLogger
// Skip array since we can't track partial initialization from nested subexpressions
if (memVar.isArray())
continue;
- if (!needsInitialization(&memVar, tokenlist.isCPP())) {
+ if (!needsInitialization(&memVar)) {
if (!var->isPointer())
partial = true;
continue;
@@ -8286,7 +8284,7 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
return read;
if (Token::Match(tok->astParent(), "%assign%") && astIsLHS(tok))
return Action::Invalid;
- if (isLikelyStreamRead(isCPP(), tok->astParent()))
+ if (isLikelyStreamRead(tok->astParent()))
return Action::Invalid;
if (astIsContainer(tok) && ValueFlow::isContainerSizeChanged(tok, getIndirect(tok), getSettings()))
return read | Action::Invalid;
@@ -8845,7 +8843,7 @@ static void valueFlowContainerSize(TokenList& tokenlist,
continue;
}
if (nameToken->astTop() && Token::Match(nameToken->astTop()->previous(), "for|while"))
- known = !isVariableChanged(var, &settings, true);
+ known = !isVariableChanged(var, &settings);
std::vector values{ValueFlow::Value{size}};
values.back().valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
if (known)
@@ -9108,7 +9106,7 @@ static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolD
if (!rhs)
continue;
- const bool isNew = symboldatabase.isCPP() && rhs->str() == "new";
+ const bool isNew = rhs->isCpp() && rhs->str() == "new";
if (!isNew && !Token::Match(rhs->previous(), "%name% ("))
continue;
@@ -9343,7 +9341,7 @@ const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const S
if (expr && expr->values().empty()) {
valueFlowConstantFoldAST(expr->astOperand1(), settings);
valueFlowConstantFoldAST(expr->astOperand2(), settings);
- valueFlowSetConstantValue(expr, settings, true /* TODO: this is a guess */);
+ valueFlowSetConstantValue(expr, settings);
}
return expr && expr->hasKnownValue() ? &expr->values().front() : nullptr;
}
diff --git a/man/manual-premium.md b/man/manual-premium.md
index 91fb023f385..1b73d1990cb 100644
--- a/man/manual-premium.md
+++ b/man/manual-premium.md
@@ -376,7 +376,7 @@ parsing the code.
The purpose of this behaviour is that Cppcheck is meant to work without necessarily seeing the entire code.
Actually, it is recommended to not give all include paths.
While it is useful for Cppcheck to see the declaration of a class when checking the implementation of its members,
-passing standard library headers is discouraged, because the analysis will not wor fully and lead to a longer checking
+passing standard library headers is discouraged, because the analysis will not work fully and lead to a longer checking
time. For such cases, .cfg files are the preferred way to provide information about the implementation of functions and
types to Cppcheck, see below for more information.
diff --git a/man/manual.md b/man/manual.md
index 8b7447a2a9e..421daf1112f 100644
--- a/man/manual.md
+++ b/man/manual.md
@@ -377,7 +377,7 @@ parsing the code.
The purpose of this behaviour is that Cppcheck is meant to work without necessarily seeing the entire code.
Actually, it is recommended to not give all include paths.
While it is useful for Cppcheck to see the declaration of a class when checking the implementation of its members,
-passing standard library headers is discouraged, because the analysis will not wor fully and lead to a longer checking
+passing standard library headers is discouraged, because the analysis will not work fully and lead to a longer checking
time. For such cases, .cfg files are the preferred way to provide information about the implementation of functions and
types to Cppcheck, see below for more information.
diff --git a/releasenotes.txt b/releasenotes.txt
index a645a24a3cb..65c9e9ef90a 100644
--- a/releasenotes.txt
+++ b/releasenotes.txt
@@ -23,3 +23,5 @@ Other:
- Added '--template=simple'. It is expands to '{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]' without any additional location details.
- Removed deprecated platform type 'Unspecified'. Please use 'unspecified' instead.
- Removed deprecated 'Makefile' option 'SRCDIR'.
+- Added CMake option 'DISALLOW_THREAD_EXECUTOR' to control the inclusion of the executor which performs the analysis within a thread of the main process.
+- Removed CMake option 'USE_THREADS' in favor of 'DISALLOW_THREAD_EXECUTOR'.
\ No newline at end of file
diff --git a/test/cfg/posix.c b/test/cfg/posix.c
index 016081aa6c9..0420cf5e131 100644
--- a/test/cfg/posix.c
+++ b/test/cfg/posix.c
@@ -1035,12 +1035,13 @@ void nullPointer_pthread_create() // #12396
pthread_create(&thread, NULL, (void* (*)(void*))f_returns_NULL, NULL);
}
-void memleak_getaddrinfo()
+void memleak_getaddrinfo() // #6994
{
- //TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
struct addrinfo * res=NULL;
getaddrinfo("node", NULL, NULL, &res);
freeaddrinfo(res);
+ getaddrinfo("node", NULL, NULL, &res);
+ // cppcheck-suppress memleak
}
void memleak_mmap(int fd)
@@ -1058,6 +1059,26 @@ void * memleak_mmap2() // #8327
return NULL;
}
+void memleak_getline() { // #11043
+ char *line = NULL;
+ size_t size = 0;
+ getline(&line, &size, stdin);
+ // cppcheck-suppress memleak
+ line = NULL;
+ getline(&line, &size, stdin);
+ // cppcheck-suppress memleak
+ line = NULL;
+}
+
+void memleak_getline_array(FILE* stream) { // #12498
+ char* a[2] = { 0 };
+ size_t n;
+ getline(&a[0], &n, stream);
+ getline(&a[1], &n, stream);
+ free(a[0]);
+ free(a[1]);
+}
+
void * identicalCondition_mmap(int fd, size_t size) // #9940
{
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp
index 00ff036ccfc..179f44d4b3f 100644
--- a/test/cfg/windows.cpp
+++ b/test/cfg/windows.cpp
@@ -572,7 +572,7 @@ void memleak_AllocateAndInitializeSid()
PSID pEveryoneSID = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID);
- // TODO: enable when #6994 is implemented cppcheck-suppress memleak
+ // cppcheck-suppress memleak
}
void memleak_HeapAlloc()
diff --git a/test/cli/fuzz-crash/crash-4d4e80f09d4733a9f724282d60ee4e3c3a143b61 b/test/cli/fuzz-crash/crash-4d4e80f09d4733a9f724282d60ee4e3c3a143b61
new file mode 100644
index 00000000000..de445fa92bf
--- /dev/null
+++ b/test/cli/fuzz-crash/crash-4d4e80f09d4733a9f724282d60ee4e3c3a143b61
@@ -0,0 +1 @@
+d o(i*a){n b;*a=&b;if(a)r{}}
\ No newline at end of file
diff --git a/test/cli/fuzz-crash/crash-7bac85061edab7fdce2889f02ea3a044242a3920 b/test/cli/fuzz-crash/crash-7bac85061edab7fdce2889f02ea3a044242a3920
new file mode 100644
index 00000000000..d9de20d6e55
--- /dev/null
+++ b/test/cli/fuzz-crash/crash-7bac85061edab7fdce2889f02ea3a044242a3920
@@ -0,0 +1 @@
+a,typedef U typedef,U,i
\ No newline at end of file
diff --git a/test/cli/fuzz-crash/crash-82986578453ec2056069c70846571775b10dfbcb b/test/cli/fuzz-crash/crash-82986578453ec2056069c70846571775b10dfbcb
new file mode 100644
index 00000000000..d658e27570f
--- /dev/null
+++ b/test/cli/fuzz-crash/crash-82986578453ec2056069c70846571775b10dfbcb
@@ -0,0 +1 @@
+namespace d=S
\ No newline at end of file
diff --git a/test/cli/fuzz-crash/crash-e000709d155e9c993795748ba31fddacbd5a86ac b/test/cli/fuzz-crash/crash-e000709d155e9c993795748ba31fddacbd5a86ac
new file mode 100644
index 00000000000..6f94840a159
--- /dev/null
+++ b/test/cli/fuzz-crash/crash-e000709d155e9c993795748ba31fddacbd5a86ac
@@ -0,0 +1 @@
+{for(()s)}
\ No newline at end of file
diff --git a/test/cli/fuzz-crash/crash-f4ec019b9a1f357d036a9bc3c2cb6fb10a0c3ded b/test/cli/fuzz-crash/crash-f4ec019b9a1f357d036a9bc3c2cb6fb10a0c3ded
new file mode 100644
index 00000000000..7f948841a94
--- /dev/null
+++ b/test/cli/fuzz-crash/crash-f4ec019b9a1f357d036a9bc3c2cb6fb10a0c3ded
@@ -0,0 +1 @@
+o k(){t*data;{memcpy(data,,sizeof\)}}
\ No newline at end of file
diff --git a/test/cli/testutils.py b/test/cli/testutils.py
index b076f27d4d2..a6692bde8bc 100644
--- a/test/cli/testutils.py
+++ b/test/cli/testutils.py
@@ -97,6 +97,21 @@ def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe
arg_clang = '--clang=' + str(os.environ['TEST_CPPCHECK_INJECT_CLANG'])
args.append(arg_clang)
+ if 'TEST_CPPCHECK_INJECT_EXECUTOR' in os.environ:
+ found_jn = False
+ found_executor = False
+ for arg in args:
+ if arg.startswith('-j') and arg != '-j1':
+ found_jn = True
+ continue
+ if arg.startswith('--executor'):
+ found_executor = True
+ continue
+ # only add '--executor' if we are actually using multiple jobs
+ if found_jn and not found_executor:
+ arg_executor = '--executor=' + str(os.environ['TEST_CPPCHECK_INJECT_EXECUTOR'])
+ args.append(arg_executor)
+
logging.info(exe + ' ' + ' '.join(args))
p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd)
try:
diff --git a/test/fixture.cpp b/test/fixture.cpp
index 30acf65935f..d3dac189535 100644
--- a/test/fixture.cpp
+++ b/test/fixture.cpp
@@ -115,14 +115,11 @@ void TestFixture::teardownTest()
{
teardownTestInternal();
- // TODO: enable
- /*
- {
- const std::string s = errout.str();
+ {
+ const std::string s = errout_str();
if (!s.empty())
throw std::runtime_error("unconsumed ErrorLogger err: " + s);
- }
- */
+ }
{
const std::string s = output_str();
if (!s.empty())
@@ -429,7 +426,7 @@ void TestFixture::reportErr(const ErrorMessage &msg)
if (msg.severity == Severity::information && msg.id == "normalCheckLevelMaxBranches")
return;
const std::string errormessage(msg.toString(mVerbose, mTemplateFormat, mTemplateLocation));
- errout << errormessage << std::endl;
+ mErrout << errormessage << std::endl;
}
void TestFixture::setTemplateFormat(const std::string &templateFormat)
diff --git a/test/fixture.h b/test/fixture.h
index e151e520ed8..7527f3261bd 100644
--- a/test/fixture.h
+++ b/test/fixture.h
@@ -254,12 +254,17 @@ class TestFixture : public ErrorLogger {
return s;
}
- std::ostringstream errout;
+ std::string errout_str() {
+ std::string s = mErrout.str();
+ mErrout.str("");
+ return s;
+ }
const Settings settingsDefault;
private:
std::ostringstream mOutput;
+ std::ostringstream mErrout;
void reportOut(const std::string &outmsg, Color c = Color::Reset) override;
void reportErr(const ErrorMessage &msg) override;
diff --git a/test/helpers.h b/test/helpers.h
index 9326b7255eb..d134b6121d1 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -20,10 +20,12 @@
#define helpersH
#include "settings.h"
+#include "standards.h"
#include "tokenize.h"
#include "tokenlist.h"
#include
+#include
#include
#include
#include
@@ -31,23 +33,19 @@
class Token;
class Preprocessor;
class SuppressionList;
+class ErrorLogger;
namespace simplecpp {
struct DUI;
}
-class givenACodeSampleToTokenize {
-private:
- const Settings settings;
- Tokenizer tokenizer;
-
+class SimpleTokenizer {
public:
- explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true)
- : tokenizer(settings, nullptr) {
+ SimpleTokenizer(ErrorLogger& errorlogger, const char sample[], bool cpp = true)
+ : tokenizer{settings, &errorlogger}
+ {
std::istringstream iss(sample);
- if (createOnly)
- tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c");
- else
- tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c");
+ if (!tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c"))
+ throw std::runtime_error("creating tokens failed");
}
Token* tokens() {
@@ -57,6 +55,34 @@ class givenACodeSampleToTokenize {
const Token* tokens() const {
return tokenizer.tokens();
}
+
+private:
+ const Settings settings;
+ Tokenizer tokenizer;
+};
+
+class SimpleTokenList
+{
+public:
+
+ explicit SimpleTokenList(const char code[], Standards::Language lang = Standards::Language::CPP)
+ {
+ std::istringstream iss(code);
+ if (!list.createTokens(iss, lang))
+ throw std::runtime_error("creating tokens failed");
+ }
+
+ Token* front() {
+ return list.front();
+ }
+
+ const Token* front() const {
+ return list.front();
+ }
+
+private:
+ const Settings settings;
+ TokenList list{&settings};
};
diff --git a/test/test64bit.cpp b/test/test64bit.cpp
index 04ae74d5a5e..97ba363c01d 100644
--- a/test/test64bit.cpp
+++ b/test/test64bit.cpp
@@ -44,9 +44,6 @@ class Test64BitPortability : public TestFixture {
#define check(code) check_(code, __FILE__, __LINE__)
void check_(const char code[], const char* file, int line) {
- // Clear the error buffer..
- errout.str("");
-
// Tokenize..
Tokenizer tokenizer(settings, this);
std::istringstream istr(code);
@@ -63,13 +60,13 @@ class Test64BitPortability : public TestFixture {
"void f() {\n"
" CharArray foo = \"\";\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct T { std::vector*a[2][2]; };\n" // #11560
"void f(T& t, int i, int j) {\n"
" t.a[i][j] = new std::vector;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void novardecl() {
@@ -78,7 +75,7 @@ class Test64BitPortability : public TestFixture {
"{\n"
" a = p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void functionpar() {
@@ -87,65 +84,65 @@ class Test64BitPortability : public TestFixture {
" int a = p;\n"
" return a + 4;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout_str());
check("int foo(int p[])\n"
"{\n"
" int a = p;\n"
" return a + 4;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout_str());
check("int foo(int p[])\n"
"{\n"
" int *a = p;\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout_str());
check("void foo(int x)\n"
"{\n"
" int *p = x;\n"
" *p = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout_str());
check("int f(const char *p) {\n" // #4659
" return 6 + p[2] * 256;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int foo(int *p) {\n" // #6096
" bool a = p;\n"
" return a;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::array f();\n"
"void g() {\n"
" std::array a = f();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::array f(int x);\n"
"void g(int i) {\n"
" std::array a = f(i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("typedef std::array Array;\n"
"Array f(int x);\n"
"void g(int i) {\n"
" Array a = f(i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("typedef std::array Array;\n"
"Array f();\n"
"void g(int i) {\n"
" Array a = f();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S {\n" // #9951
" enum E { E0 };\n"
@@ -154,12 +151,12 @@ class Test64BitPortability : public TestFixture {
"void f() {\n"
" std::array a = S::g(S::E::E0);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("char* f(char* p) {\n"
" return p ? p : 0;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void structmember() {
@@ -167,7 +164,7 @@ class Test64BitPortability : public TestFixture {
"void f(struct Foo *foo) {\n"
" int i = foo->p;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout_str());
check("struct S {\n" // #10145
" enum class E { e1, e2 };\n"
@@ -177,7 +174,7 @@ class Test64BitPortability : public TestFixture {
"void f(S& s) {\n"
" s.e = S::E::e1;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void ptrcompare() {
@@ -185,7 +182,7 @@ class Test64BitPortability : public TestFixture {
check("void foo(int *p) {\n"
" int a = (p != NULL);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void ptrarithmetic() {
@@ -194,74 +191,74 @@ class Test64BitPortability : public TestFixture {
" int x = 10;\n"
" int *a = p + x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = x + p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = x * x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout_str());
check("void foo(int *start, int *end) {\n"
" int len;\n"
" int len = end + 10 - start;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnIssues() {
check("void* foo(int i) {\n"
" return i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an integer in a function with pointer return type is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an integer in a function with pointer return type is not portable.\n", errout_str());
check("void* foo(int* i) {\n"
" return i;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void* foo() {\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int foo(int i) {\n"
" return i;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct Foo {};\n"
"\n"
"int* dostuff(Foo foo) {\n"
" return foo;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int foo(char* c) {\n"
" return c;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout_str());
check("int foo(char* c) {\n"
" return 1+c;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout_str());
check("std::string foo(char* c) {\n"
" return c;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int foo(char *a, char *b) {\n" // #4486
" return a + 1 - b;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct s {\n" // 4642
" int i;\n"
@@ -269,13 +266,13 @@ class Test64BitPortability : public TestFixture {
"int func(struct s *p) {\n"
" return 1 + p->i;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("static void __iomem *f(unsigned int port_no) {\n"
" void __iomem *mmio = hpriv->mmio;\n"
" return mmio + (port_no * 0x80);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #7247: don't check return statements in nested functions..
check("int foo() {\n"
@@ -283,7 +280,7 @@ class Test64BitPortability : public TestFixture {
" const char * name() { return \"abc\"; }\n"
" } table;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #7451: Lambdas
check("const int* test(std::vector outputs, const std::string& text) {\n"
@@ -291,7 +288,7 @@ class Test64BitPortability : public TestFixture {
" [&](int ele) { return \"test\" == text; });\n"
" return nullptr;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S {\n" // #12159
" std::future f() const {\n"
@@ -303,7 +300,7 @@ class Test64BitPortability : public TestFixture {
" auto x = s->f();\n"
" return x.get();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
};
diff --git a/test/testassert.cpp b/test/testassert.cpp
index 735d87dddfa..e6beeb33a05 100644
--- a/test/testassert.cpp
+++ b/test/testassert.cpp
@@ -35,9 +35,6 @@ class TestAssert : public TestFixture {
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const char *filename = "test.cpp") {
- // Clear the error buffer..
- errout.str("");
-
// Tokenize..
Tokenizer tokenizer(settings, this);
std::istringstream istr(code);
@@ -65,7 +62,7 @@ class TestAssert : public TestFixture {
" return a;\n"
"}\n"
"assert(foo() == 3);");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check(
"int foo(int a) {\n"
@@ -73,7 +70,7 @@ class TestAssert : public TestFixture {
" return b;\n"
"}\n"
"assert(foo(1) == 2);");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void functionCallInAssert() {
@@ -84,7 +81,7 @@ class TestAssert : public TestFixture {
" return a;\n"
"}\n"
"assert(foo() == 3);");
- ASSERT_EQUALS("[test.cpp:6]: (warning) Assert statement calls a function which may have desired side effects: 'foo'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (warning) Assert statement calls a function which may have desired side effects: 'foo'.\n", errout_str());
// Ticket #4937 "false positive: Assert calls a function which may have desired side effects"
check("struct SquarePack {\n"
@@ -96,7 +93,7 @@ class TestAssert : public TestFixture {
"void foo() {\n"
" assert( !SquarePack::isRank1Or8(push2) );\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct SquarePack {\n"
" static bool isRank1Or8( Square &sq ) {\n"
@@ -107,7 +104,7 @@ class TestAssert : public TestFixture {
"void foo() {\n"
" assert( !SquarePack::isRank1Or8(push2) );\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout_str());
check("struct SquarePack {\n"
" static bool isRank1Or8( Square *sq ) {\n"
@@ -118,7 +115,7 @@ class TestAssert : public TestFixture {
"void foo() {\n"
" assert( !SquarePack::isRank1Or8(push2) );\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout_str());
check("struct SquarePack {\n"
" static bool isRank1Or8( Square *sq ) {\n"
@@ -129,7 +126,7 @@ class TestAssert : public TestFixture {
"void foo() {\n"
" assert( !SquarePack::isRank1Or8(push2) );\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct Geometry {\n"
" int nbv;\n"
@@ -140,7 +137,7 @@ class TestAssert : public TestFixture {
"void Geometry::ReadGeometry() {\n"
" assert(empty());\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void memberFunctionCallInAssert() {
@@ -150,7 +147,7 @@ class TestAssert : public TestFixture {
"void foo(SquarePack s) {\n"
" assert( s.Foo() );\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (warning) Assert statement calls a function which may have desired side effects: 'Foo'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (warning) Assert statement calls a function which may have desired side effects: 'Foo'.\n", errout_str());
check("struct SquarePack {\n"
" int Foo() const;\n"
@@ -158,7 +155,7 @@ class TestAssert : public TestFixture {
"void foo(SquarePack* s) {\n"
" assert( s->Foo() );\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct SquarePack {\n"
" static int Foo();\n"
@@ -166,14 +163,14 @@ class TestAssert : public TestFixture {
"void foo(SquarePack* s) {\n"
" assert( s->Foo() );\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct SquarePack {\n"
"};\n"
"void foo(SquarePack* s) {\n"
" assert( s->Foo() );\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void assignmentInAssert() {
@@ -182,54 +179,54 @@ class TestAssert : public TestFixture {
" assert(a = 2);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout_str());
check("void f(int a) {\n"
" assert(a == 2);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a, int b) {\n"
" assert(a == 2 && (b = 1));\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Assert statement modifies 'b'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Assert statement modifies 'b'.\n", errout_str());
check("void f() {\n"
" int a; a = 0;\n"
" assert(a += 2);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout_str());
check("void f() {\n"
" int a; a = 0;\n"
" assert(a *= 2);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout_str());
check("void f() {\n"
" int a; a = 0;\n"
" assert(a -= 2);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout_str());
check("void f() {\n"
" int a = 0;\n"
" assert(a--);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout_str());
check("void f() {\n"
" int a = 0;\n"
" assert(--a);\n"
" return a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout_str());
check("void f() {\n"
" assert(std::all_of(first, last, []() {\n"
@@ -238,19 +235,19 @@ class TestAssert : public TestFixture {
" return tmp == expected;\n"
" }));\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void crash() {
check("void foo() {\n"
" assert(sizeof(struct { int a[x++]; })==sizeof(int));\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo() {\n" // #9790
" assert(kad_bucket_hash(&(kad_guid) { .bytes = { 0 } }, & (kad_guid){.bytes = { 0 }}) == -1);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
};
diff --git a/test/testastutils.cpp b/test/testastutils.cpp
index 0d05b90072d..9140b16e561 100644
--- a/test/testastutils.cpp
+++ b/test/testastutils.cpp
@@ -181,7 +181,7 @@ class TestAstUtils : public TestFixture {
ASSERT_LOC(tokenizer.tokenize(istr, cpp ? "test.cpp" : "test.c"), file, line);
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1));
const Token * const tok2 = Token::findsimplematch(tok1->next(), tokStr2, strlen(tokStr2));
- return (isSameExpression)(cpp, false, tok1, tok2, library, false, true, nullptr);
+ return (isSameExpression)(false, tok1, tok2, library, false, true, nullptr);
}
void isSameExpressionTestInternal(bool cpp) {
@@ -229,7 +229,7 @@ class TestAstUtils : public TestFixture {
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern, strlen(endPattern));
- return (isVariableChanged)(tok1, tok2, 1, false, &settingsDefault, /*cpp*/ true);
+ return (isVariableChanged)(tok1, tok2, 1, false, &settingsDefault);
}
void isVariableChangedTest() {
@@ -407,7 +407,7 @@ class TestAstUtils : public TestFixture {
const Token* const start = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
const Token* const end = Token::findsimplematch(start, endPattern, strlen(endPattern));
const Token* const expr = Token::findsimplematch(tokenizer.tokens(), var, strlen(var));
- return (findExpressionChanged)(expr, start, end, &settings, /*cpp*/ true);
+ return (findExpressionChanged)(expr, start, end, &settings);
}
void isExpressionChangedTest()
diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp
index 4cc23f727c6..666023b5f3c 100644
--- a/test/testautovariables.cpp
+++ b/test/testautovariables.cpp
@@ -34,9 +34,6 @@ class TestAutoVariables : public TestFixture {
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], bool inconclusive = true, const char* filename = "test.cpp") {
- // Clear the error buffer..
- errout.str("");
-
const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
// Tokenize..
@@ -169,21 +166,21 @@ class TestAutoVariables : public TestFixture {
" int num = 2;\n"
" *res = #\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("void func1(int **res)\n"
"{\n"
" int num = 2;\n"
" res = #\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str());
check("void func1(int **res)\n"
"{\n"
" int num = 2;\n"
" foo.res = #\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar2() {
@@ -195,7 +192,7 @@ class TestAutoVariables : public TestFixture {
" int num = 2;\n"
" *res = #\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("class Fred {\n"
" void func1(int **res);\n"
@@ -205,7 +202,7 @@ class TestAutoVariables : public TestFixture {
" int num = 2;\n"
" res = #\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str());
check("class Fred {\n"
" void func1(int **res);\n"
@@ -215,7 +212,7 @@ class TestAutoVariables : public TestFixture {
" int num = 2;\n"
" foo.res = #\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar3() { // ticket #2925
@@ -224,7 +221,7 @@ class TestAutoVariables : public TestFixture {
" int x[100];\n"
" *p = x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar4() { // ticket #2928
@@ -233,7 +230,7 @@ class TestAutoVariables : public TestFixture {
" static int x[100];\n"
" *p = x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar5() { // ticket #2926
@@ -242,7 +239,7 @@ class TestAutoVariables : public TestFixture {
" char a;\n"
" ab->a = &a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar6() { // ticket #2931
@@ -251,14 +248,14 @@ class TestAutoVariables : public TestFixture {
" char a[10];\n"
" x->str = a;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(struct X *x)\n"
"{\n"
" char a[10];\n"
" x->str = a;\n"
"}", true);
- ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar7() { // ticket #3066
@@ -268,7 +265,7 @@ class TestAutoVariables : public TestFixture {
" target->parent = &scrollpane->widget;\n"
" return scrollpane;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar8() {
@@ -276,12 +273,12 @@ class TestAutoVariables : public TestFixture {
" int i = 0;\n"
" p = &i;\n"
"}", false);
- ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("void foo(std::string& s) {\n"
" s = foo;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar9() {
@@ -292,7 +289,7 @@ class TestAutoVariables : public TestFixture {
" FP fp;\n"
" p = &fn.i;\n"
"}", false);
- ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("struct FN {int i;};\n"
"struct FP {FN* f};\n"
@@ -301,7 +298,7 @@ class TestAutoVariables : public TestFixture {
" FP fp;\n"
" p = &p_fp->i;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct FN {int i;};\n"
"struct FP {FN* f};\n"
@@ -310,100 +307,100 @@ class TestAutoVariables : public TestFixture {
" FP fp;\n"
" p = &fp.f->i;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar10() { // #2930 - assignment of function parameter
check("void foo(char* p) {\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str());
check("void foo(int b) {\n"
" b = foo(b);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str());
check("void foo(int b) {\n"
" b += 1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str());
check("void foo(std::string s) {\n"
" s = foo(b);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str());
check("void foo(char* p) {\n" // don't warn for self assignment, there is another warning for this
" p = p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* p) {\n"
" if (!p) p = buf;\n"
" *p = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* p) {\n"
" if (!p) p = buf;\n"
" do_something(p);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* p) {\n"
" while (!p) p = buf;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* p) {\n"
" p = 0;\n"
" asm(\"somecmd\");\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(Foo* p) {\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str());
check("class Foo {};\n"
"void foo(Foo p) {\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str());
check("void foo(Foo p) {\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(int& p) {\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("double foo(double d) {\n" // #5005
" int i = d;\n"
" d = i;\n"
" return d;"
"}",false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(int* ptr) {\n" // #4793
" ptr++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str());
check("void foo(int* ptr) {\n" // #3177
" --ptr;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str());
check("void foo(struct S* const x) {\n" // #7839
" ++x->n;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar11() { // #4641 - fp, assign local struct member address to function parameter
@@ -414,7 +411,7 @@ class TestAutoVariables : public TestFixture {
" struct A a = bar();\n"
" *p = &(*a.data)[0];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" char data[10];\n"
@@ -423,26 +420,26 @@ class TestAutoVariables : public TestFixture {
" struct A a = bar();\n"
" *p = &a.data[0];\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("void f(char **out) {\n"
" struct S *p = glob;\n"
" *out = &p->data;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #4998
check("void f(s8**out) {\n"
" s8 *p;\n" // <- p is pointer => no error
" *out = &p[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(s8**out) {\n"
" s8 p[10];\n" // <- p is array => error
" *out = &p[1];\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input
@@ -472,7 +469,7 @@ class TestAutoVariables : public TestFixture {
" goto label;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar15() { // Ticket #6538
@@ -485,7 +482,7 @@ class TestAutoVariables : public TestFixture {
" return &darkOutline;\n"
" return 0;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar16() { // Ticket #8114
@@ -493,7 +490,7 @@ class TestAutoVariables : public TestFixture {
" int dummy;\n"
" *result = (&dummy < ptr);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar_array1() {
@@ -502,7 +499,7 @@ class TestAutoVariables : public TestFixture {
" int num=2;"
" arr[0]=#\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar_array2() {
@@ -514,7 +511,7 @@ class TestAutoVariables : public TestFixture {
" int num=2;"
" arr[0]=#\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar_array3() {
@@ -522,7 +519,7 @@ class TestAutoVariables : public TestFixture {
" std::string a = \"abc\";\n"
" argv[0] = &a[0];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char* c[]) {\n"
" char a[] = \"abc\";\n"
@@ -534,7 +531,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n"
"[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n",
- errout.str());
+ errout_str());
check("struct String {\n"
" String& operator=(const char* c) { m = c; return *this; }\n"
@@ -549,7 +546,7 @@ class TestAutoVariables : public TestFixture {
" char a[] = \"abc\";\n"
" *s = &a[0];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar_normal() {
@@ -558,7 +555,7 @@ class TestAutoVariables : public TestFixture {
" XPoint DropPoint;\n"
" ds->location_data = (XtPointer *)&DropPoint;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar_ptrptr() { // #6596
@@ -566,7 +563,7 @@ class TestAutoVariables : public TestFixture {
" char dead_slot;\n"
" matches[0] = (char *)&dead_slot;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
}
void testautovar_return1() {
@@ -575,7 +572,7 @@ class TestAutoVariables : public TestFixture {
" int num=2;"
" return #"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3]: (error) Returning pointer to local variable 'num' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3]: (error) Returning pointer to local variable 'num' that will be invalid when returning.\n", errout_str());
}
void testautovar_return2() {
@@ -587,7 +584,7 @@ class TestAutoVariables : public TestFixture {
" int num=2;"
" return #"
"}");
- ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6]: (error) Returning pointer to local variable 'num' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6]: (error) Returning pointer to local variable 'num' that will be invalid when returning.\n", errout_str());
}
void testautovar_return3() {
@@ -597,7 +594,7 @@ class TestAutoVariables : public TestFixture {
" void *&value = tls[id];"
" return &value;"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar_return4() {
@@ -606,7 +603,7 @@ class TestAutoVariables : public TestFixture {
" int cond2;\n"
" dostuff([&cond2]() { return &cond2; });\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar_return5() { // #11465
@@ -614,7 +611,7 @@ class TestAutoVariables : public TestFixture {
"const std::type_info* f() {\n"
" return &typeid(S);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar_extern() {
@@ -623,7 +620,7 @@ class TestAutoVariables : public TestFixture {
" extern struct foo f;\n"
" return &f;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testautovar_reassigned() {
@@ -633,7 +630,7 @@ class TestAutoVariables : public TestFixture {
" dostuff(pcb);\n"
" pcb->root0 = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(cb* pcb) {\n"
" int root0;\n"
@@ -642,7 +639,7 @@ class TestAutoVariables : public TestFixture {
" if (condition) return;\n" // <- not reassigned => error
" pcb->root0 = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("void foo(cb* pcb) {\n"
" int root0;\n"
@@ -651,7 +648,7 @@ class TestAutoVariables : public TestFixture {
" if (condition)\n"
" pcb->root0 = 0;\n" // <- conditional reassign => error
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("struct S { int *p; };\n"
"void g(struct S* s) {\n"
@@ -666,7 +663,7 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n"
"[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", // duplicate
- errout.str());
+ errout_str());
}
void testinvaliddealloc() {
@@ -686,33 +683,33 @@ class TestAutoVariables : public TestFixture {
"[test.cpp:5]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
"[test.cpp:7]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
"[test.cpp:9]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
- "[test.cpp:11]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
+ "[test.cpp:11]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str());
check("void func1(char * ptr) {\n"
" free(ptr);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void func1() {\n"
" char* tmp1[256];\n"
" init(tmp1);\n"
" delete tmp1[34];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void func1() {\n"
" static char tmp1[256];\n"
" char *p = tmp1;\n"
" free(p);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a static variable (tmp1) results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a static variable (tmp1) results in undefined behaviour.\n", errout_str());
check("char tmp1[256];\n"
"void func1() {\n"
" char *p; if (x) p = tmp1;\n"
" free(p);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a global variable (tmp1) results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a global variable (tmp1) results in undefined behaviour.\n", errout_str());
check("void f()\n"
"{\n"
@@ -723,7 +720,7 @@ class TestAutoVariables : public TestFixture {
" free(psz_title);\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #2298 new check: passing stack-address to free()
check("int main() {\n"
@@ -731,44 +728,44 @@ class TestAutoVariables : public TestFixture {
" free(&p);\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str());
check("int main() {\n"
" int i;\n"
" free(&i);\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str());
// #5732
check("int main() {\n"
" long (*pKoeff)[256] = new long[9][256];\n"
" delete[] pKoeff;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int main() {\n"
" long *pKoeff[256];\n"
" delete[] pKoeff;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str());
check("int main() {\n"
" long *pKoeff[256];\n"
" free (pKoeff);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str());
check("void foo() {\n"
" const intPtr& intref = Getter();\n"
" delete intref;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void test() {\n"
" MyObj& obj = *new MyObj;\n"
" delete &obj;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #6506
check("struct F {\n"
@@ -780,7 +777,7 @@ class TestAutoVariables : public TestFixture {
" char *c2 = 0;\n"
" F().free(&c2);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class foo {\n"
" void free(void* );\n"
@@ -789,14 +786,14 @@ class TestAutoVariables : public TestFixture {
" free(&dst_copy);\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #6551
check("bool foo( ) {\n"
" SwTxtFld * pTxtFld = GetFldTxtAttrAt();\n"
" delete static_cast(&pTxtFld->GetAttr());\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #8910
check("void f() {\n"
@@ -806,14 +803,14 @@ class TestAutoVariables : public TestFixture {
" else data = (RGNDATA *)stack;\n"
" if ((char *)data != stack) free (data);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #8923
check("void f(char **args1, char *args2[]) {\n"
" free((char **)args1);\n"
" free((char **)args2);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #10097
check("struct Array {\n"
@@ -821,7 +818,7 @@ class TestAutoVariables : public TestFixture {
" std::array* m_Arr{};\n"
"};\n"
"Array arr;\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #8174
check("struct S {};\n"
@@ -830,7 +827,7 @@ class TestAutoVariables : public TestFixture {
" S* p = &s;\n"
" free(p);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Deallocation of an auto-variable (s) results in undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Deallocation of an auto-variable (s) results in undefined behaviour.\n", errout_str());
check("void f(bool b, int* q) {\n"
" int i;\n"
@@ -838,7 +835,7 @@ class TestAutoVariables : public TestFixture {
" if (!b)\n"
" free(p);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct E { int* i; };\n" // #11768
"struct C { E e; };\n"
@@ -848,13 +845,13 @@ class TestAutoVariables : public TestFixture {
" delete[] e->i;\n"
" return 0;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" S* p = &g();\n"
" delete p;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testinvaliddealloc_input() {
@@ -862,12 +859,12 @@ class TestAutoVariables : public TestFixture {
check("void f(int* a[]) {\n"
" free(a);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a[]) {\n"
" free(a);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int* a[]) {\n"
" int * p = *a;\n"
@@ -875,13 +872,13 @@ class TestAutoVariables : public TestFixture {
" int ** q = a;\n"
" free(q);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a[]) {\n"
" int * p = a;\n"
" free(p);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testinvaliddealloc_string() {
@@ -901,7 +898,7 @@ class TestAutoVariables : public TestFixture {
"[test.cpp:5]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour.\n"
"[test.cpp:6]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour.\n"
"[test.cpp:9]: (error) Deallocation of a pointer pointing to a string literal (\"abc\") results in undefined behaviour.\n",
- errout.str());
+ errout_str());
check("void f() {\n"
" char *ptr = malloc(10);\n"
@@ -911,7 +908,7 @@ class TestAutoVariables : public TestFixture {
" if (ptr != empty_str)\n"
" free(ptr);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testinvaliddealloc_C() {
@@ -920,7 +917,7 @@ class TestAutoVariables : public TestFixture {
" struct context c;\n"
" SVN_ERR(delete(&c, root_baton, src_entry, pool));\n"
"}\n", false, "test.c");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testassign1() { // Ticket #1819
@@ -928,7 +925,7 @@ class TestAutoVariables : public TestFixture {
" EventPtr event = *eventP;\n"
" *actionsP = &event->actions;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testassign2() { // Ticket #2765
@@ -936,7 +933,7 @@ class TestAutoVariables : public TestFixture {
" struct my_s *mr = global_structure_pointer;\n"
" *datap = &mr->value;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void assignAddressOfLocalArrayToGlobalPointer() {
@@ -945,7 +942,7 @@ class TestAutoVariables : public TestFixture {
" int x[10];\n"
" p = x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'p' will use pointer to local variable 'x'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'p' will use pointer to local variable 'x'.\n", errout_str());
check("int *p;\n"
"void f() {\n"
@@ -953,7 +950,7 @@ class TestAutoVariables : public TestFixture {
" p = x;\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void assignAddressOfLocalVariableToGlobalPointer() {
@@ -962,7 +959,7 @@ class TestAutoVariables : public TestFixture {
" int x;\n"
" p = &x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'p' will use pointer to local variable 'x'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'p' will use pointer to local variable 'x'.\n", errout_str());
check("int *p;\n"
"void f() {\n"
@@ -970,7 +967,7 @@ class TestAutoVariables : public TestFixture {
" p = &x;\n"
" p = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void assignAddressOfLocalVariableToMemberVariable() {
@@ -981,7 +978,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" int *ptr;\n"
"};");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'ptr' will use pointer to local variable 'x'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'ptr' will use pointer to local variable 'x'.\n", errout_str());
check("struct A {\n"
" void f() {\n"
@@ -991,7 +988,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" int *ptr;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnLocalVariable1() {
@@ -1002,7 +999,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning pointer to local variable 'str' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("char *foo()\n" // use ValueFlow
"{\n"
@@ -1012,7 +1009,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3] -> [test.cpp:5]: (error) Returning pointer to local variable 'str' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("class Fred {\n"
" char *foo();\n"
@@ -1024,7 +1021,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning pointer to local variable 'str' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("char * format_reg(char *outbuffer_start) {\n"
" return outbuffer_start;\n"
@@ -1034,7 +1031,7 @@ class TestAutoVariables : public TestFixture {
" char *tp = temp;\n"
" tp = format_reg(tp);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnLocalVariable2() {
@@ -1043,7 +1040,7 @@ class TestAutoVariables : public TestFixture {
" char str[100] = {0};\n"
" return str;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class Fred {\n"
" std::string foo();\n"
@@ -1053,7 +1050,7 @@ class TestAutoVariables : public TestFixture {
" char str[100] = {0};\n"
" return str;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -1063,14 +1060,14 @@ class TestAutoVariables : public TestFixture {
" char q[] = \"AAAAAAAAAAAA\";\n"
" return &q[1];\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout_str());
check("char *foo()\n"
"{\n"
" static char q[] = \"AAAAAAAAAAAA\";\n"
" return &q[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("char *foo()\n"
"{\n"
@@ -1079,7 +1076,7 @@ class TestAutoVariables : public TestFixture {
"p = &q[1];\n"
"return p;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout_str());
}
void returnLocalVariable4() { // x+y
@@ -1089,7 +1086,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("char *foo(int y) {\n"
" char x[10] = {0};\n"
@@ -1097,7 +1094,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
}
void returnLocalVariable5() { // cast
@@ -1107,7 +1104,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
}
void returnLocalVariable6() { // valueflow
@@ -1116,7 +1113,7 @@ class TestAutoVariables : public TestFixture {
" int p = &x;\n"
" return p;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", errout_str());
}
void returnReference1() {
@@ -1126,35 +1123,35 @@ class TestAutoVariables : public TestFixture {
" int& x = s;\n"
" return x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Reference to local variable returned.\n", errout_str());
check("std::string &foo()\n"
"{\n"
" std::string s;\n"
" return s;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout_str());
check("std::vector &foo()\n"
"{\n"
" std::vector v;\n"
" return v;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout_str());
check("std::vector &foo()\n"
"{\n"
" static std::vector v;\n"
" return v;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector &foo()\n"
"{\n"
" thread_local std::vector v;\n"
" return v;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string hello()\n"
"{\n"
@@ -1165,7 +1162,7 @@ class TestAutoVariables : public TestFixture {
"{\n"
" return hello();\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Reference to temporary returned.\n", errout_str());
// make sure scope is used in function lookup
check("class Fred {\n"
@@ -1176,7 +1173,7 @@ class TestAutoVariables : public TestFixture {
"std::string &f() {\n"
" return hello();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string hello() {\n"
" return std::string();\n"
@@ -1185,7 +1182,7 @@ class TestAutoVariables : public TestFixture {
"std::string &f() {\n"
" return hello();\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str());
check("std::string hello() {\n"
" return \"foo\";\n"
@@ -1194,7 +1191,7 @@ class TestAutoVariables : public TestFixture {
"std::string &f() {\n"
" return hello().substr(1);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str());
check("class Foo;\n"
"Foo hello() {\n"
@@ -1204,7 +1201,7 @@ class TestAutoVariables : public TestFixture {
"Foo& f() {\n"
" return hello();\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Reference to temporary returned.\n", errout_str());
// make sure function overloads are handled properly
check("class Foo;\n"
@@ -1219,7 +1216,7 @@ class TestAutoVariables : public TestFixture {
"Foo& f() {\n"
" return hello(true);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("Foo hello() {\n"
" return Foo();\n"
@@ -1228,7 +1225,7 @@ class TestAutoVariables : public TestFixture {
"Foo& f() {\n" // Unknown type - might be a reference
" return hello();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference2() {
@@ -1240,7 +1237,7 @@ class TestAutoVariables : public TestFixture {
" std::string s;\n"
" return s;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Reference to local variable returned.\n", errout_str());
check("class Fred {\n"
" std::vector &foo();\n"
@@ -1250,7 +1247,7 @@ class TestAutoVariables : public TestFixture {
" std::vector v;\n"
" return v;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Reference to local variable returned.\n", errout_str());
check("class Fred {\n"
" std::vector &foo();\n"
@@ -1260,7 +1257,7 @@ class TestAutoVariables : public TestFixture {
" static std::vector v;\n"
" return v;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class Fred {\n"
" std::string &f();\n"
@@ -1273,7 +1270,7 @@ class TestAutoVariables : public TestFixture {
"{\n"
" return hello();\n"
"}");
- ASSERT_EQUALS("[test.cpp:10]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (error) Reference to temporary returned.\n", errout_str());
check("class Fred {\n"
" std::string hello();\n"
@@ -1287,7 +1284,7 @@ class TestAutoVariables : public TestFixture {
"{\n"
" return hello();\n"
"}");
- ASSERT_EQUALS("[test.cpp:11]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:11]: (error) Reference to temporary returned.\n", errout_str());
check("class Bar;\n"
"Bar foo() {\n"
@@ -1296,7 +1293,7 @@ class TestAutoVariables : public TestFixture {
"Bar& bar() {\n"
" return foo();\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str());
check("std::map foo() {\n"
" return something;\n"
@@ -1304,7 +1301,7 @@ class TestAutoVariables : public TestFixture {
"std::map& bar() {\n"
" return foo();\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout_str());
check("Bar foo() {\n"
" return something;\n"
@@ -1312,7 +1309,7 @@ class TestAutoVariables : public TestFixture {
"Bar& bar() {\n" // Unknown type - might be a typedef to a reference type
" return foo();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Don't crash with function in unknown scope (#4076)
check("X& a::Bar() {}"
"X& foo() {"
@@ -1326,7 +1323,7 @@ class TestAutoVariables : public TestFixture {
" rd = ret;\n"
" return rd;\n"
"}", false);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// Returning reference to global variable
@@ -1335,7 +1332,7 @@ class TestAutoVariables : public TestFixture {
"double & f() {\n"
" return a;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference5() {
@@ -1355,7 +1352,7 @@ class TestAutoVariables : public TestFixture {
" return ra;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference6() {
@@ -1363,7 +1360,7 @@ class TestAutoVariables : public TestFixture {
" Fred &fred(*new Fred);\n"
" return fred;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference7() { // 3791 - false positive for overloaded function
@@ -1372,14 +1369,14 @@ class TestAutoVariables : public TestFixture {
"std::string &b() {\n"
" return a(12);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string &a(int);\n"
"std::string a();\n"
"std::string &b() {\n"
" return a(12);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference8() {
@@ -1388,14 +1385,14 @@ class TestAutoVariables : public TestFixture {
" int& value = *it;\n"
" return value;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference9() {
check("int& f(bool b, int& x, int& y) {\n"
" return b ? x : y;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference10() {
@@ -1404,14 +1401,14 @@ class TestAutoVariables : public TestFixture {
" A a;\n"
" return a.f();\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Reference to temporary returned.\n", errout_str());
check("class A { int& f() const; };\n"
"int& g() {\n"
" A a;\n"
" return a.f();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference11() {
@@ -1419,19 +1416,19 @@ class TestAutoVariables : public TestFixture {
"int& g() {\n"
" return A::f();\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str());
check("class A { static int& f(); };\n"
"int& g() {\n"
" return A::f();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("namespace A { int& f(); }\n"
"int& g() {\n"
" return A::f();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference12() {
@@ -1439,14 +1436,14 @@ class TestAutoVariables : public TestFixture {
"auto g() {\n"
" return &A::f;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class A { static int& f(); };\n"
"auto g() {\n"
" auto x = &A::f;\n"
" return x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference13() {
@@ -1455,14 +1452,14 @@ class TestAutoVariables : public TestFixture {
"int& foo(size_t i) {\n"
" return ((std::vector*)vp)->at(i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector v;\n"
"void* vp = &v;\n"
"int& foo(size_t i) {\n"
" return static_cast*>(vp)->at(i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference14() {
@@ -1475,7 +1472,7 @@ class TestAutoVariables : public TestFixture {
"void* &A::f() {\n"
" return g()->m;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference15() {
@@ -1488,7 +1485,7 @@ class TestAutoVariables : public TestFixture {
"const int& f(const T&) {\n"
" return f();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("template \n"
"int g();\n"
@@ -1496,19 +1493,19 @@ class TestAutoVariables : public TestFixture {
"const int& f(const T&) {\n"
" return g();\n"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
}
void returnReference16() {
check("int& f(std::tuple& x) {\n"
" return std::get<0>(x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int& f(int x) {\n"
" return std::get<0>(std::make_tuple(x));\n"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
}
void returnReference17() {
@@ -1516,7 +1513,7 @@ class TestAutoVariables : public TestFixture {
"int& f() {\n"
" return g();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference18() {
@@ -1525,7 +1522,7 @@ class TestAutoVariables : public TestFixture {
"int& g(int* x) {\n"
" return f(*x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #9597
@@ -1533,7 +1530,7 @@ class TestAutoVariables : public TestFixture {
check("struct C : B {\n"
" const B &f() const { return (const B &)*this; }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #9536
@@ -1544,7 +1541,7 @@ class TestAutoVariables : public TestFixture {
"int& b() {\n"
" return a()();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto a() {\n"
" return []() -> int& {\n"
@@ -1555,20 +1552,20 @@ class TestAutoVariables : public TestFixture {
"const int& c() {\n"
" return a()();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::function a();\n"
"int& b() {\n"
" return a()();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9889
check("int f(std::vector>& v, int i) {\n"
" auto& j = v[i]();\n"
" return j;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #9530
@@ -1576,7 +1573,7 @@ class TestAutoVariables : public TestFixture {
check("int& f(int& x) {\n"
" return {x};\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference22() {
@@ -1584,7 +1581,7 @@ class TestAutoVariables : public TestFixture {
" std::unique_ptr p = std::make_unique(1);\n"
" return *p;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout_str());
check("void g(const std::unique_ptr&);\n"
"int& f() {\n"
@@ -1592,7 +1589,7 @@ class TestAutoVariables : public TestFixture {
" g(p);\n"
" return *p;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Reference to local variable returned.\n", errout_str());
check("void g(std::shared_ptr);\n"
"int& f() {\n"
@@ -1600,26 +1597,26 @@ class TestAutoVariables : public TestFixture {
" g(p);\n"
" return *p;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::shared_ptr g();\n"
"int& f() {\n"
" return *g();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::unique_ptr g();\n"
"int& f() {\n"
" return *g();\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str());
check("struct A { int x; };\n"
"int& f() {\n"
" std::unique_ptr p = std::make_unique();\n"
" return p->x;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout_str());
}
void returnReference23() {
@@ -1627,7 +1624,7 @@ class TestAutoVariables : public TestFixture {
"const std::vector& f() {\n"
" return *g();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference24()
@@ -1638,7 +1635,7 @@ class TestAutoVariables : public TestFixture {
"const A& a() {\n"
" return A();\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout_str());
}
void returnReference25()
@@ -1650,7 +1647,7 @@ class TestAutoVariables : public TestFixture {
"int& h() {\n"
" return g();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReference26()
@@ -1660,7 +1657,7 @@ class TestAutoVariables : public TestFixture {
" int& s{ x };\n"
" return s;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout_str());
}
void returnReferenceFunction() {
@@ -1673,7 +1670,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:6]: (error) Reference to local variable returned.\n",
- errout.str());
+ errout_str());
check("int& f(int& a) {\n"
" return a;\n"
@@ -1684,7 +1681,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("int* f(int * x) {\n"
" return x;\n"
@@ -1692,7 +1689,7 @@ class TestAutoVariables : public TestFixture {
"int * g(int x) {\n"
" return f(&x);\n"
"}");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout_str());
check("int* f(int * x) {\n"
" x = nullptr;\n"
@@ -1701,7 +1698,7 @@ class TestAutoVariables : public TestFixture {
"int * g(int x) {\n"
" return f(&x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(int& a) {\n"
" return a;\n"
@@ -1710,7 +1707,7 @@ class TestAutoVariables : public TestFixture {
" int x = 0;\n"
" return f(x);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str());
check("int& f(int a) {\n"
" return a;\n"
@@ -1719,7 +1716,7 @@ class TestAutoVariables : public TestFixture {
" int x = 0;\n"
" return f(x);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Reference to local variable returned.\n", errout_str());
check("int f(int a) {\n"
" return a;\n"
@@ -1728,14 +1725,14 @@ class TestAutoVariables : public TestFixture {
" int x = 0;\n"
" return f(x);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str());
check("template\n"
"int& f(int& x, T y) {\n"
" x += y;\n"
" return x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReferenceContainer() {
@@ -1743,31 +1740,31 @@ class TestAutoVariables : public TestFixture {
" std::vector x;\n"
" return x[0];\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout_str());
check("auto& f() {\n"
" std::vector x;\n"
" return x.front();\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to local variable returned.\n", errout_str());
check("std::vector g();\n"
"auto& f() {\n"
" return g().front();\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout_str());
check("auto& f() {\n"
" return std::vector{1}.front();\n"
"}");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) Reference to temporary returned.\n", errout_str());
check("struct A { int foo; };\n"
"int& f(std::vector v) {\n"
" auto it = v.begin();\n"
" return it->foo;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout_str());
check("template \n"
"const V& get_default(const T& t, const K& k, const V& v) {\n"
@@ -1782,7 +1779,7 @@ class TestAutoVariables : public TestFixture {
true);
ASSERT_EQUALS(
"[test.cpp:2] -> [test.cpp:4] -> [test.cpp:9] -> [test.cpp:9]: (error, inconclusive) Reference to local variable returned.\n",
- errout.str());
+ errout_str());
check("template \n"
"const V& get_default(const T& t, const K& k, const V& v) {\n"
@@ -1796,33 +1793,33 @@ class TestAutoVariables : public TestFixture {
true);
ASSERT_EQUALS(
"[test.cpp:2] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:8]: (error, inconclusive) Reference to temporary returned.\n",
- errout.str());
+ errout_str());
check("struct A { int foo; };\n"
"int& f(std::vector& v) {\n"
" auto it = v.begin();\n"
" return it->foo;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("static std::vector A[2];\n"
"static std::vector B;\n"
"std::vector& g(int i) {\n"
" return i ? A[i] : B;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReferenceLiteral() {
check("const std::string &a() {\n"
" return \"foo\";\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str());
check("const std::string a() {\n"
" return \"foo\";\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const std::string& f(const std::string& x) { return x; }\n"
"const std::string &a() {\n"
@@ -1830,65 +1827,65 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:1] -> [test.cpp:1] -> [test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n",
- errout.str());
+ errout_str());
check("const char * f(const char * x) { return x; }\n"
"const std::string &a() {\n"
" return f(\"foo\");\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str());
}
void returnReferenceCalculation() {
check("const std::string &a(const std::string& str) {\n"
" return \"foo\" + str;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str());
check("int& operator<<(int out, int path) {\n"
" return out << path;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str());
check("std::ostream& operator<<(std::ostream& out, const std::string& path) {\n"
" return out << path;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::ostream& operator<<(std::ostream* out, const std::string& path) {\n"
" return *out << path;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("Unknown1& operator<<(Unknown1 out, Unknown2 path) {\n"
" return out << path;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int& a(int b) {\n"
" return 2*(b+1);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str());
check("const std::string &a(const std::string& str) {\n"
" return str;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const std::string &a(int bar) {\n"
" return foo(bar + 1);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const std::string a(const std::string& str) {\n"
" return \"foo\" + str;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int& incValue(int& value) {\n"
" return ++value;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReferenceLambda() {
@@ -1899,7 +1896,7 @@ class TestAutoVariables : public TestFixture {
" return false;\n"
" });\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #5844
check("map const &getVariableTable() {\n"
@@ -1909,13 +1906,13 @@ class TestAutoVariables : public TestFixture {
" }();\n"
"return s_var;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #7583
check("Command& foo() {\n"
" return f([]() -> int { return 1; });\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReferenceInnerScope() {
@@ -1928,16 +1925,16 @@ class TestAutoVariables : public TestFixture {
" };\n"
" return _make(_Wrapper::call, pmf);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnReferenceRecursive() {
check("int& f() { return f(); }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int& g(int& i) { return i; }\n"
"int& f() { return g(f()); }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void extendedLifetime() {
@@ -1947,7 +1944,7 @@ class TestAutoVariables : public TestFixture {
" const int& x = h();\n"
" return [&] { return x; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning lambda that captures local variable 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning lambda that captures local variable 'x' that will be invalid when returning.\n", errout_str());
check("void g(int*);\n"
"int h();\n"
@@ -1955,7 +1952,7 @@ class TestAutoVariables : public TestFixture {
" const int& x = h();\n"
" return &x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout_str());
check("void g(int*);\n"
"int h();\n"
@@ -1966,7 +1963,7 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Using pointer that is a temporary.\n"
"[test.cpp:4] -> [test.cpp:5]: (error) Using reference to dangling temporary.\n",
- errout.str());
+ errout_str());
check("void g(int*);\n"
"int h();\n"
@@ -1974,7 +1971,7 @@ class TestAutoVariables : public TestFixture {
" const int& x = h();\n"
" g(&x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct Data {\n"
" std::string path;\n"
@@ -1983,7 +1980,7 @@ class TestAutoVariables : public TestFixture {
" const Data& data = getData();\n"
" return data.path.c_str();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingReference() {
@@ -1993,14 +1990,14 @@ class TestAutoVariables : public TestFixture {
" return r;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Non-local reference variable 'r' to local variable 'k'\n",
- errout.str());
+ errout_str());
check("int &f( int & k )\n"
"{\n"
" static int &r = k;\n"
" return r;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingTempReference() {
@@ -2011,7 +2008,7 @@ class TestAutoVariables : public TestFixture {
" const auto& str_cref2 = g(std::string(\"hello\"));\n"
" std::cout << str_cref2 << std::endl;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:5] -> [test.cpp:6]: (error) Using reference to dangling temporary.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:5] -> [test.cpp:6]: (error) Using reference to dangling temporary.\n", errout_str());
// Lifetime extended
check("std::string g(const std::string& str_cref) {\n"
@@ -2021,14 +2018,14 @@ class TestAutoVariables : public TestFixture {
" const auto& str_cref2 = g(std::string(\"hello\"));\n"
" std::cout << str_cref2 << std::endl;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("char f() {\n"
" char c = 0;\n"
" char&& cr = std::move(c);\n"
" return cr;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9987
check("void g(std::vector);\n"
@@ -2036,7 +2033,7 @@ class TestAutoVariables : public TestFixture {
" std::vector&& v = {};\n"
" g(std::move(v));\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void g(std::vector);\n"
"std::vector h();\n"
@@ -2044,7 +2041,7 @@ class TestAutoVariables : public TestFixture {
" std::vector&& v = h();\n"
" g(std::move(v));\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11087
check("struct S1 {\n"
@@ -2057,7 +2054,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:6] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:7]: (error) Using reference to dangling temporary.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int& g() const { return i; }\n"
@@ -2068,7 +2065,7 @@ class TestAutoVariables : public TestFixture {
" const int& i = a()->g();\n"
" return i;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" const int& g() const { return i; }\n"
@@ -2081,7 +2078,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:2] -> [test.cpp:7] -> [test.cpp:8]: (error) Using reference to dangling temporary.\n",
- errout.str());
+ errout_str());
check("struct S1 {\n"
" auto get() -> auto& { return val; }\n"
@@ -2099,7 +2096,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:11] -> [test.cpp:2] -> [test.cpp:11] -> [test.cpp:12]: (error) Using reference to dangling temporary.\n",
- errout.str());
+ errout_str());
check("struct C {\n"
" std::vector> v;\n"
@@ -2117,14 +2114,14 @@ class TestAutoVariables : public TestFixture {
" auto e = (*it)->v.begin();\n"
" const int& x = (*e)[1];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int* g();\n" // #11188
"void f() {\n"
" const auto& p = g();\n"
" if (p != nullptr) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("template\n"
"void f(const std::vector& v) {\n"
@@ -2134,7 +2131,7 @@ class TestAutoVariables : public TestFixture {
" a = b;\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("using namespace std;\n" // #10971
"struct S { int i = 3; };\n"
@@ -2146,7 +2143,7 @@ class TestAutoVariables : public TestFixture {
" const S& s = *g();\n"
" (void)s.i;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Using reference to dangling temporary.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Using reference to dangling temporary.\n", errout_str());
check("std::string f() {\n" // #12173
" std::string s;\n"
@@ -2155,7 +2152,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" return s;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testglobalnamespace() {
@@ -2169,7 +2166,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnParameterAddress() {
@@ -2178,28 +2175,28 @@ class TestAutoVariables : public TestFixture {
" return &y;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'y' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'y' that will be invalid when returning.\n", errout_str());
check("int ** foo(int * y)\n"
"{\n"
" return &y;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'y' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'y' that will be invalid when returning.\n", errout_str());
check("const int * foo(const int & y)\n"
"{\n"
" return &y;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int * foo(int * y)\n"
"{\n"
" return y;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct s { void *p; };\n"
"extern struct s* f(void);\n"
@@ -2209,7 +2206,7 @@ class TestAutoVariables : public TestFixture {
" *q = &r->p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void testconstructor() { // Ticket #5478 - crash while checking a constructor
@@ -2219,6 +2216,7 @@ class TestAutoVariables : public TestFixture {
" return const_tree_iterator(foo);\n"
" }\n"
"};");
+ ASSERT_EQUALS("[test.cpp:4]: (error) Reference to temporary returned.\n", errout_str());
}
void variableIsUsedInScope() {
@@ -2237,30 +2235,30 @@ class TestAutoVariables : public TestFixture {
" auto l = [&](){ return a; };\n"
" return l;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" int a = 1;\n"
" return [&](){ return a; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto f(int a) {\n"
" return [&](){ return a; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto f(int a) {\n"
" auto p = &a;\n"
" return [=](){ return p; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto g(int& a) {\n"
" int p = a;\n"
" return [&](){ return p; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'p' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'p' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" return [=](){\n"
@@ -2268,7 +2266,7 @@ class TestAutoVariables : public TestFixture {
" return [&](){ return a; };\n"
" };\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto f(int b) {\n"
" return [=](int a){\n"
@@ -2276,30 +2274,30 @@ class TestAutoVariables : public TestFixture {
" return [&](){ return a; };\n"
" };\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto g(int& a) {\n"
" return [&](){ return a; };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto g(int a) {\n"
" auto p = a;\n"
" return [=](){ return p; };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto g(int& a) {\n"
" auto p = a;\n"
" return [=](){ return p; };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto g(int& a) {\n"
" int& p = a;\n"
" return [&](){ return p; };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("template\n"
"void g(F);\n"
@@ -2307,51 +2305,51 @@ class TestAutoVariables : public TestFixture {
" int x;\n"
" return g([&]() { return x; });\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto f() {\n"
" int i = 0;\n"
" return [&i] {};\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" int i = 0;\n"
" return [i] {};\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto f() {\n"
" int i = 0;\n"
" return [=, &i] {};\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" int i = 0;\n"
" int j = 0;\n"
" return [=, &i] { return j; };\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" int i = 0;\n"
" return [&, i] {};\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto f() {\n"
" int i = 0;\n"
" int j = 0;\n"
" return [&, i] { return j; };\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'j' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'j' that will be invalid when returning.\n", errout_str());
check("auto f(int& i) {\n"
" int j = 0;\n"
" return [=, &i] { return j; };\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int*);\n"
"auto g(int y) {\n"
@@ -2360,7 +2358,7 @@ class TestAutoVariables : public TestFixture {
" g(&x);\n"
" };\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" int x;\n"
@@ -2372,7 +2370,7 @@ class TestAutoVariables : public TestFixture {
" ap->x;\n"
" };\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeContainer() {
@@ -2380,21 +2378,21 @@ class TestAutoVariables : public TestFixture {
" auto it = x.begin();\n"
" return it;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector::iterator f() {\n"
" std::vector x;\n"
" auto it = x.begin();\n"
" return it;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" std::vector x;\n"
" auto it = std::begin(x);\n"
" return it;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str());
check("int* f() {\n"
" std::vector x;\n"
@@ -2403,7 +2401,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto f() {\n"
" std::vector x;\n"
@@ -2412,7 +2410,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A { int foo; };\n"
"int* f(std::vector v) {\n"
@@ -2421,13 +2419,13 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::vector::iterator f(std::vector x) {\n"
" auto it = x.begin();\n"
" return it;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str());
check("auto f() {\n"
" std::vector x;\n"
@@ -2436,7 +2434,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto f() {\n"
" std::vector x;\n"
@@ -2445,7 +2443,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto f() {\n"
" std::vector x;\n"
@@ -2454,7 +2452,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::vector f() {\n"
" int i = 0;\n"
@@ -2464,7 +2462,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::vector f() {\n"
" std::vector r;\n"
@@ -2476,7 +2474,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:5] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2487,7 +2485,7 @@ class TestAutoVariables : public TestFixture {
"};");
ASSERT_EQUALS(
"[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2499,7 +2497,7 @@ class TestAutoVariables : public TestFixture {
"};");
ASSERT_EQUALS(
"[test.cpp:5] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:6]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" std::vector m;\n"
@@ -2513,7 +2511,7 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n"
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n", // duplicate
- errout.str());
+ errout_str());
check("std::vector::iterator f(std::vector v) {\n"
" for(auto it = v.begin();it != v.end();it++) {\n"
@@ -2523,7 +2521,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("const char * f() {\n"
" std::string ba(\"hello\");\n"
@@ -2531,7 +2529,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'ba' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("template \n"
"const V* get_default(const T& t, const K& k, const V* v) {\n"
@@ -2546,14 +2544,14 @@ class TestAutoVariables : public TestFixture {
true);
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:9] -> [test.cpp:8] -> [test.cpp:9]: (error, inconclusive) Returning pointer to local variable 'x' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::vector g();\n"
"auto f() {\n"
" return g().begin();\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Returning iterator that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::vector g();\n"
"std::vector::iterator f() {\n"
@@ -2562,13 +2560,13 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4]: (error) Using iterator that is a temporary.\n"
"[test.cpp:3] -> [test.cpp:4]: (error) Returning iterator that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::vector g();\n"
"int& f() {\n"
" return *g().begin();\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2577,7 +2575,7 @@ class TestAutoVariables : public TestFixture {
" v.push_back(s);\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector f() {\n"
" const char * s = \"hello\";\n"
@@ -2585,46 +2583,46 @@ class TestAutoVariables : public TestFixture {
" v.push_back(s);\n"
" return v;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto f() {\n"
" static std::vector x;\n"
" return x.begin();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string g() {\n"
" std::vector v;\n"
" return v.data();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector::iterator f(std::vector* v) {\n"
" return v->begin();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector::iterator f(std::vector* v) {\n"
" std::vector* v = new std::vector();\n"
" return v->begin();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(std::vector v) {\n"
" return *v.begin();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(std::vector v) {\n"
" return v.end() - v.begin();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto g() {\n"
" std::vector v;\n"
" return {v, [v]() { return v.data(); }};\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("template\n"
"void g(F);\n"
@@ -2632,7 +2630,7 @@ class TestAutoVariables : public TestFixture {
" std::vector v;\n"
" return g([&]() { return v.data(); });\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector g();\n"
"struct A {\n"
@@ -2642,7 +2640,7 @@ class TestAutoVariables : public TestFixture {
" m.insert(m.end(), v.begin(), v.end());\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool b) {\n"
" std::vector v = {1};\n"
@@ -2652,7 +2650,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" return v.back() == 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class A {\n"
" int f( P p ) {\n"
@@ -2663,7 +2661,7 @@ class TestAutoVariables : public TestFixture {
" std::map< S, B > m1;\n"
" std::map< S, B > m2;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2672,47 +2670,47 @@ class TestAutoVariables : public TestFixture {
" v.push_back(&x);\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("size_t f(const std::string& x) {\n"
" std::string y = \"x\";\n"
" return y.find(x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string* f();\n"
"const char* g() {\n"
" std::string* var = f();\n"
" return var->c_str();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string f() {\n"
" std::vector data{};\n"
" data.push_back('a');\n"
" return std::string{ data.data(), data.size() };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector f() {\n"
" char a = 0;\n"
" return std::vector{&a};\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout_str());
check("std::vector* g();\n"
"int& f() {\n"
" auto* p = g();\n"
" return p->front();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector> g();\n"
"void f() {\n"
" for(auto& x:g())\n"
" std::sort(x.begin(), x.end());\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2726,7 +2724,7 @@ class TestAutoVariables : public TestFixture {
"};\n");
ASSERT_EQUALS(
"[test.cpp:8] -> [test.cpp:8] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:4]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2739,7 +2737,7 @@ class TestAutoVariables : public TestFixture {
" int i = 0;\n"
" a.add(&i);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::vector v;\n"
@@ -2752,7 +2750,7 @@ class TestAutoVariables : public TestFixture {
" a.add(&i);\n"
" }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() {\n"
" int i;\n"
@@ -2763,7 +2761,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" return i;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int* get(std::vector& container) {\n"
" Sequence seq(container);\n"
@@ -2772,20 +2770,20 @@ class TestAutoVariables : public TestFixture {
" }\n"
" return &*seq.begin();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string f(std::string Str, int first, int last) {\n"
" return { Str.begin() + first, Str.begin() + last + 1 };\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string f(std::string s) {\n"
" std::string r = { s.begin(), s.end() };\n"
" return r;\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::vector> mA;\n"
@@ -2794,7 +2792,7 @@ class TestAutoVariables : public TestFixture {
" mA.push_back(std::move(a));\n"
" }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::map m;\n"
@@ -2803,20 +2801,20 @@ class TestAutoVariables : public TestFixture {
" return &(r.first->second);\n"
" }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" std::queue q;\n"
" auto& h = q.emplace();\n"
" h = 1;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string f(std::string s) {\n"
" std::string ss = (\":\" + s).c_str();\n"
" return ss;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeContainerView()
@@ -2827,7 +2825,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::string_view f() {\n"
" std::string s = \"\";\n"
@@ -2836,7 +2834,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::string_view f() {\n"
" std::string s = \"\";\n"
@@ -2844,7 +2842,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::string_view f(std::string_view s) {\n"
" return s;\n"
@@ -2855,7 +2853,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("const char * f() {\n"
" std::string s;\n"
@@ -2864,7 +2862,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("const char * f() {\n"
" std::string s;\n"
@@ -2872,7 +2870,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("const char * f() {\n"
" std::string s;\n"
@@ -2881,12 +2879,12 @@ class TestAutoVariables : public TestFixture {
TODO_ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning.\n",
"",
- errout.str());
+ errout_str());
check("const char * f(std::string_view sv) {\n"
" return sv.begin();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const char * f(std::string s) {\n"
" std::string_view sv = s;\n"
@@ -2894,31 +2892,31 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::string_view f(std::string s) {\n"
" return s;\n"
"}\n");
ASSERT_EQUALS(
"[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("const char * f(const std::string& s) {\n"
" std::string_view sv = s;\n"
" return sv.begin();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string_view f(const std::string_view& sv) {\n"
" return sv;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n" // #10993
" std::string_view v = std::string();\n"
" v.data();\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n", errout_str());
check("std::string convert(std::string_view sv) { return std::string{ sv }; }\n" // #11374
"auto f() {\n"
@@ -2926,7 +2924,7 @@ class TestAutoVariables : public TestFixture {
" v.push_back(convert(\"foo\"));\n"
" return v[0];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #10532
check("std::string f(std::string ss) {\n"
@@ -2935,14 +2933,14 @@ class TestAutoVariables : public TestFixture {
" return s;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n",
- errout.str());
+ errout_str());
// #10833
check("struct A { std::string s; };\n"
"const std::string& f(A* a) {\n"
" return a ? a->s : \"\";\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str());
check("std::span f() {\n"
" std::vector v{};\n"
@@ -2950,7 +2948,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::span f() {\n"
" std::vector v;\n"
@@ -2959,7 +2957,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("std::span f() {\n"
" std::vector v;\n"
@@ -2967,7 +2965,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("int f() {\n"
" std::span s;\n"
@@ -2979,7 +2977,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
- errout.str());
+ errout_str());
check("int f() {\n"
" std::span s;\n"
@@ -2991,7 +2989,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
- errout.str());
+ errout_str());
check("int f() {\n"
" std::span s;\n"
@@ -3003,7 +3001,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
- errout.str());
+ errout_str());
check("int f() {\n"
" std::span s;\n"
@@ -3015,7 +3013,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
- errout.str());
+ errout_str());
check("int f() {\n"
" std::span s;\n"
@@ -3027,7 +3025,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
- errout.str());
+ errout_str());
}
void danglingLifetimeUniquePtr()
@@ -3038,14 +3036,14 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'p' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("int* f();\n" // #11406
"bool g() {\n"
" std::unique_ptr ptr(f());\n"
" return ptr.get();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int* f();\n"
"int* g() {\n"
@@ -3054,7 +3052,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning pointer to local variable 'ptr' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
}
void danglingLifetime() {
check("auto f() {\n"
@@ -3062,13 +3060,13 @@ class TestAutoVariables : public TestFixture {
" auto it = a.begin();\n"
" return [=](){ return it; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("auto f(std::vector a) {\n"
" auto it = a.begin();\n"
" return [=](){ return it; };\n"
"}");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str());
check("struct e {};\n"
"e * j() {\n"
@@ -3077,18 +3075,18 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning pointer to local variable 'c' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto f(std::vector& a) {\n"
" auto it = a.begin();\n"
" return [=](){ return it; };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int * f(int a[]) {\n"
" return a;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" struct b {\n"
@@ -3096,14 +3094,14 @@ class TestAutoVariables : public TestFixture {
" } d;\n"
" uint32_t *a = d.f;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Don't decay std::array
check("std::array f() {\n"
" std::array x;\n"
" return x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Make sure we don't hang
check("struct A;\n"
@@ -3111,7 +3109,7 @@ class TestAutoVariables : public TestFixture {
" using T = A[3];\n"
" A &&a = T{1, 2, 3}[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Make sure we don't hang
check("struct A;\n"
@@ -3119,7 +3117,7 @@ class TestAutoVariables : public TestFixture {
" using T = A[3];\n"
" A &&a = T{1, 2, 3}[1]();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Make sure we don't hang
check("struct A;\n"
@@ -3127,7 +3125,7 @@ class TestAutoVariables : public TestFixture {
" using T = A[3];\n"
" A &&a = T{1, 2, 3}[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Make sure we don't hang
check("struct A;\n"
@@ -3135,7 +3133,7 @@ class TestAutoVariables : public TestFixture {
" using T = A[3];\n"
" A &&a = T{1, 2, 3}[1]();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Crash #8872
check("struct a {\n"
@@ -3143,14 +3141,14 @@ class TestAutoVariables : public TestFixture {
" d(c, [&] { c->e });\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct a {\n"
" void operator()(b c) override {\n"
" d(c, [=] { c->e });\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct a {\n"
" a(char* b) {}\n"
@@ -3159,7 +3157,7 @@ class TestAutoVariables : public TestFixture {
" char c[20];\n"
" return c;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct a {\n"
" a(char* b) {}\n"
@@ -3169,7 +3167,7 @@ class TestAutoVariables : public TestFixture {
" a d = c;\n"
" return d;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" struct a {\n"
@@ -3177,14 +3175,14 @@ class TestAutoVariables : public TestFixture {
" auto g() { return v.end(); }\n"
" };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int * f(std::vector& v) {\n"
" for(int & x : v)\n"
" return &x;\n"
" return nullptr;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9275
check("struct S {\n"
@@ -3196,7 +3194,7 @@ class TestAutoVariables : public TestFixture {
" const char* msg = buf;\n"
" m = msg;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9201
check("int* f() {\n"
@@ -3204,14 +3202,14 @@ class TestAutoVariables : public TestFixture {
" static a b{0};\n"
" return &b.m;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9453
check("int *ptr;\n"
"void foo(int arr[]) {\n"
" ptr = &arr[2];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9639
check("struct Fred {\n"
@@ -3222,7 +3220,7 @@ class TestAutoVariables : public TestFixture {
" const Fred &fred = getFred();\n"
" return fred.s.c_str();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9534
check("struct A {\n"
@@ -3232,14 +3230,14 @@ class TestAutoVariables : public TestFixture {
" A& y = v[i];\n"
" return &y.x[i];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9712
check("std::string f(const char *str) {\n"
" char value[256];\n"
" return value;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9770
check("class C {\n"
@@ -3249,7 +3247,7 @@ class TestAutoVariables : public TestFixture {
" const char data[] = \"x\";\n"
" return data;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9899
check("struct A {\n"
@@ -3261,14 +3259,14 @@ class TestAutoVariables : public TestFixture {
" f(std::move(w));\n"
" }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
//Make sure we can still take the address of a reference without warning
check("int* foo() {\n"
" int& x = getX();\n"
" return &x;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct C {\n"
" int* m_x;\n"
" void foo() {\n"
@@ -3276,7 +3274,7 @@ class TestAutoVariables : public TestFixture {
" m_x = &x;\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #10090
check("struct a {\n"
@@ -3294,7 +3292,7 @@ class TestAutoVariables : public TestFixture {
" e.c = &e.d->b;\n"
" return e;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #10214
check("struct A {\n"
@@ -3307,7 +3305,7 @@ class TestAutoVariables : public TestFixture {
" [key](const auto &v) { return v.key == key; });\n"
" return (entry == lookup.end()) ? \"\" : entry->value;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9811
check("struct Base {\n"
@@ -3318,7 +3316,7 @@ class TestAutoVariables : public TestFixture {
" auto get() -> int & override { return z; }\n"
" auto getMore() -> int & { return get(); }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #10575
check("struct Data {\n"
@@ -3337,21 +3335,21 @@ class TestAutoVariables : public TestFixture {
"};\n");
ASSERT_EQUALS(
"[test.cpp:11] -> [test.cpp:10] -> [test.cpp:11]: (error) Non-local variable 'mMoreData.data1' will use pointer to local variable 'data'.\n",
- errout.str());
+ errout_str());
// #10784
check("template \n"
"auto f(int i, Ts&... xs) {\n"
" return std::tie(xs[i]...);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11362
check("int* f() {\n"
" static struct { int x; } a[] = { { 1 } };\n"
" return &a[0].x;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11666
check("template \n"
@@ -3373,7 +3371,7 @@ class TestAutoVariables : public TestFixture {
"Matrix O() {\n"
" return { {}, {} };\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11729
check("struct T {\n"
@@ -3386,7 +3384,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" std::vector v;\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeFunction() {
@@ -3396,7 +3394,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto f() {\n"
" int a;\n"
@@ -3404,7 +3402,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("template\n"
"auto by_value(T x) {\n"
@@ -3416,7 +3414,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:7] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("template\n"
"auto by_value(const T& x) {\n"
@@ -3428,7 +3426,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:7] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto by_ref(int& x) {\n"
" return [&] { return x; };\n"
@@ -3439,7 +3437,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("auto by_ref(const int& x) {\n"
" return [=] { return x; };\n"
@@ -3448,14 +3446,14 @@ class TestAutoVariables : public TestFixture {
" int i = 0;\n"
" return by_ref(i);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("auto f(int x) {\n"
" int a;\n"
" std::tie(a) = x;\n"
" return a;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::pair\n"
"str_pair(std::string const & a, std::string const & b) {\n"
@@ -3468,7 +3466,7 @@ class TestAutoVariables : public TestFixture {
" par.push_back(str_pair(\"param3\", \"prop_c\"));\n"
" return par;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeUserConstructor()
@@ -3486,7 +3484,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int* i;\n"
@@ -3500,7 +3498,7 @@ class TestAutoVariables : public TestFixture {
true);
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error, inconclusive) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int* i;\n"
@@ -3512,7 +3510,7 @@ class TestAutoVariables : public TestFixture {
" return a;\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" int& i;\n"
@@ -3527,7 +3525,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int& i;\n"
@@ -3542,7 +3540,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int* i;\n"
@@ -3557,7 +3555,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int* i;\n"
@@ -3570,7 +3568,7 @@ class TestAutoVariables : public TestFixture {
" return a;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Returning object that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int* i;\n"
@@ -3584,7 +3582,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" std::string v;\n"
@@ -3596,7 +3594,7 @@ class TestAutoVariables : public TestFixture {
" std::string s;\n"
" return A{s};\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::string_view v;\n"
@@ -3610,7 +3608,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int* i;\n"
@@ -3622,7 +3620,7 @@ class TestAutoVariables : public TestFixture {
" return A{0};\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:8]: (error) Returning object that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int n;\n"
@@ -3632,7 +3630,7 @@ class TestAutoVariables : public TestFixture {
" A m(4);\n"
" return m;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct B {};\n"
"struct A {\n"
@@ -3643,7 +3641,7 @@ class TestAutoVariables : public TestFixture {
" A m(B{});\n"
" return m;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" A(std::vector &filenames)\n"
@@ -3656,7 +3654,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:8] -> [test.cpp:7] -> [test.cpp:8]: (error) Returning object that points to local variable 'files' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct S {\n"
" explicit S(std::string& s);\n"
@@ -3666,7 +3664,7 @@ class TestAutoVariables : public TestFixture {
" return S(m);\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S {\n"
" std::string msg;\n"
@@ -3677,7 +3675,7 @@ class TestAutoVariables : public TestFixture {
" return S(s.c_str());\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S {\n"
" explicit S(const char* p) { m = p; }\n"
@@ -3690,7 +3688,7 @@ class TestAutoVariables : public TestFixture {
" s.g();\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeAggegrateConstructor() {
@@ -3704,7 +3702,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int& x;\n"
@@ -3716,7 +3714,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int& x;\n"
@@ -3729,7 +3727,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int& x;\n"
@@ -3742,7 +3740,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int& x;\n"
@@ -3754,7 +3752,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" const int& x;\n"
@@ -3764,7 +3762,7 @@ class TestAutoVariables : public TestFixture {
" int i = 0;\n"
" return A{x, i};\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" const int& x;\n"
@@ -3773,14 +3771,14 @@ class TestAutoVariables : public TestFixture {
"A f(int& x) {\n"
" return A{x, x};\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { int i; const int& j; };\n"
"A f(int& x) {\n"
" int y = 0;\n"
" return A{y, x};\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct a {\n"
" std::string m;\n"
@@ -3789,7 +3787,7 @@ class TestAutoVariables : public TestFixture {
" std::array m {};\n"
" return { m.data() };\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeInitList() {
@@ -3801,7 +3799,7 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n"
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate
- errout.str());
+ errout_str());
check("std::vector f() {\n"
" int i = 0;\n"
@@ -3811,7 +3809,7 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n"
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate
- errout.str());
+ errout_str());
check("std::vector f() {\n"
" int i = 0;\n"
@@ -3820,12 +3818,12 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n"
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate
- errout.str());
+ errout_str());
check("std::vector f(int& x) {\n"
" return {&x, &x};\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector f() {\n"
" std::set x;\n"
@@ -3833,7 +3831,7 @@ class TestAutoVariables : public TestFixture {
" x.insert(\"2\");\n"
" return { x.begin(), x.end() };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeImplicitConversion() {
@@ -3842,7 +3840,7 @@ class TestAutoVariables : public TestFixture {
" std::string ba(\"hello\");\n"
" return ba.c_str();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { A(const char *a); };\n"
"A f() {\n"
@@ -3850,7 +3848,7 @@ class TestAutoVariables : public TestFixture {
" A bp = ba.c_str();\n"
" return bp;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { A(const char *a); };\n"
"std::vector f() {\n"
@@ -3859,7 +3857,7 @@ class TestAutoVariables : public TestFixture {
" v.push_back(ba.c_str());\n"
" return v;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string f(const std::string& x) {\n"
" const char c[] = \"\";\n"
@@ -3867,7 +3865,7 @@ class TestAutoVariables : public TestFixture {
" return x + c;\n"
" return \"\";\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::string f(const std::string& x) {\n"
" const char c[] = \"123\";\n"
@@ -3875,7 +3873,7 @@ class TestAutoVariables : public TestFixture {
" return c + 1;\n"
" return \"\";\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingTemporaryLifetime() {
@@ -3889,7 +3887,7 @@ class TestAutoVariables : public TestFixture {
" C c(\"\");\n"
" while (c.f()) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const int& g(const int& x) {\n"
" return x;\n"
@@ -3900,7 +3898,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:1] -> [test.cpp:2] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:6]: (error) Using pointer that is a temporary.\n",
- errout.str());
+ errout_str());
check("QString f() {\n"
" QString a(\"dummyValue\");\n"
@@ -3909,7 +3907,7 @@ class TestAutoVariables : public TestFixture {
" return c;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4]: (error) Using pointer that is a temporary.\n",
- errout.str());
+ errout_str());
check("auto f(std::string s) {\n"
" const char *x = s.substr(1,2).c_str();\n"
@@ -3917,21 +3915,21 @@ class TestAutoVariables : public TestFixture {
" return *i;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4]: (error) Using iterator that is a temporary.\n",
- errout.str());
+ errout_str());
check("std::string f() {\n"
" std::stringstream tmp;\n"
" const std::string &str = tmp.str();\n"
" return std::string(str.c_str(), 1);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int get_value();\n"
"const int &get_reference1() {\n"
" const int &x = get_value();\n"
" return x;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to temporary returned.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to temporary returned.\n", errout_str());
check("int get_value();\n"
"const int &get_reference2() {\n"
@@ -3940,13 +3938,13 @@ class TestAutoVariables : public TestFixture {
" return x2;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:5]: (error) Reference to temporary returned.\n",
- errout.str());
+ errout_str());
check("const std::string& getState() {\n"
" static const std::string& state = \"\";\n"
" return state;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct var {\n"
" void fun();\n"
@@ -3959,7 +3957,7 @@ class TestAutoVariables : public TestFixture {
" auto a = T(GetTemp().c_str());\n"
" a->fun();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" std::map m_;\n"
@@ -3973,7 +3971,7 @@ class TestAutoVariables : public TestFixture {
" (void)m->first;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using iterator that is a temporary.\n",
- errout.str());
+ errout_str());
check("void f(bool b) {\n"
" std::vector ints = g();\n"
@@ -3983,7 +3981,7 @@ class TestAutoVariables : public TestFixture {
" for (auto it = ptr->begin(); it != ptr->end(); ++it)\n"
" {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct String {\n" // #10469
" void Append(uint8_t Val);\n"
@@ -3995,7 +3993,7 @@ class TestAutoVariables : public TestFixture {
" Append(Val);\n"
" }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11057
check("struct S {\n"
@@ -4005,7 +4003,7 @@ class TestAutoVariables : public TestFixture {
" const S a[] = { { i } };\n"
" for (const auto& s : a) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("std::vector f(const std::vector& args) {\n" // #9773
" std::vector cargs;\n"
@@ -4018,7 +4016,7 @@ class TestAutoVariables : public TestFixture {
" std::vector cargs = f({ \"0\", \"0\" });\n"
" (void)cargs;\n"
"};\n");
- ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using object that is a temporary.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using object that is a temporary.\n", errout_str());
check("struct C {\n" // #9194
" const int& m;\n"
@@ -4029,7 +4027,7 @@ class TestAutoVariables : public TestFixture {
" C c(42);\n"
" return c.get();\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:7] -> [test.cpp:8]: (error) Using object that is a temporary.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:7] -> [test.cpp:8]: (error) Using object that is a temporary.\n", errout_str());
// #11298
check("struct S {\n"
@@ -4049,7 +4047,7 @@ class TestAutoVariables : public TestFixture {
" if (u.h()) {}\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11442
check("const std::string& f(const P< std::string >& value) {\n"
@@ -4057,7 +4055,7 @@ class TestAutoVariables : public TestFixture {
" return value.get() == nullptr ? empty : *value;\n"
"}\n",
true);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11472
check("namespace N {\n"
@@ -4067,7 +4065,7 @@ class TestAutoVariables : public TestFixture {
" return p != nullptr ? *p : *reinterpret_cast(&i);\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11609
check("struct S {\n"
@@ -4077,7 +4075,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" std::map m;\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #11628
check("std::vector* g();\n"
@@ -4085,7 +4083,7 @@ class TestAutoVariables : public TestFixture {
" std::unique_ptr> p(g());\n"
" if (!p) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void danglingLifetimeBorrowedMembers()
@@ -4108,7 +4106,7 @@ class TestAutoVariables : public TestFixture {
" func1(&rech.dat);\n"
" func2(rech.k);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { int x; };\n"
"A* g();\n"
@@ -4117,7 +4115,7 @@ class TestAutoVariables : public TestFixture {
" (*ap)->x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:4] -> [test.cpp:5]: (error) Using pointer that is a temporary.\n",
- errout.str());
+ errout_str());
check("struct A { int* x; };\n"
"A g();\n"
@@ -4125,7 +4123,7 @@ class TestAutoVariables : public TestFixture {
" int* x = g().x;\n"
" (void)*x + 1;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { int x; };\n"
"struct B { A* a; }\n"
@@ -4134,7 +4132,7 @@ class TestAutoVariables : public TestFixture {
" int* x = &g()->a.x;\n"
" (void)*x + 1;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { int x; };\n"
"struct B { A* g(); };\n"
@@ -4144,7 +4142,7 @@ class TestAutoVariables : public TestFixture {
" (*ap)->x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:6]: (error) Using pointer that is a temporary.\n",
- errout.str());
+ errout_str());
}
void danglingLifetimeClassMemberFunctions()
@@ -4159,7 +4157,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:7]: (error) Returning pointer that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct Fred\n"
"{\n"
@@ -4178,7 +4176,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:9] -> [test.cpp:14] -> [test.cpp:13] -> [test.cpp:14]: (error) Returning pointer to local variable 'fred' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int i;\n"
@@ -4191,7 +4189,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:8]: (error) Returning object that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct A {\n"
" int i;\n"
@@ -4202,7 +4200,7 @@ class TestAutoVariables : public TestFixture {
"auto g() {\n"
" return A().f();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" int* i;\n"
@@ -4216,7 +4214,7 @@ class TestAutoVariables : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:9] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:4] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
- errout.str());
+ errout_str());
check("struct S {\n"
" int i{};\n"
@@ -4233,7 +4231,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" *p = ret;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void invalidLifetime() {
@@ -4245,7 +4243,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" f();\n"
"}");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using lambda that captures local variable 'b' that is out of scope.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using lambda that captures local variable 'b' that is out of scope.\n", errout_str());
check("void f(bool b) {\n"
" int* x;\n"
@@ -4257,7 +4255,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'y' that is out of scope.\n",
- errout.str());
+ errout_str());
check("void foo(int a) {\n"
" std::function f;\n"
@@ -4267,7 +4265,7 @@ class TestAutoVariables : public TestFixture {
" f();\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct a {\n"
" b();\n"
@@ -4276,7 +4274,7 @@ class TestAutoVariables : public TestFixture {
"void a::b() {\n"
" c.end()\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void b(char f[], char c[]) {\n"
" std::string d(c); {\n"
@@ -4284,7 +4282,7 @@ class TestAutoVariables : public TestFixture {
" b(f, e.c_str())\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool b) {\n"
" std::string s;\n"
@@ -4294,11 +4292,11 @@ class TestAutoVariables : public TestFixture {
" }\n"
" std::cout << s;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int &a[];\n"
"void b(){int *c = a};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A {\n"
" int x;\n"
@@ -4312,7 +4310,7 @@ class TestAutoVariables : public TestFixture {
" };\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("namespace test {\n"
"class Foo {};\n"
@@ -4331,7 +4329,7 @@ class TestAutoVariables : public TestFixture {
" f(bar);\n"
"}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class Foo {};\n"
"struct Bar {\n"
@@ -4348,7 +4346,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" f(bar);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("namespace test {\n"
"class Foo {};\n"
@@ -4366,7 +4364,7 @@ class TestAutoVariables : public TestFixture {
" f(bar);\n"
"}\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:12]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:12]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("class Foo {};\n"
"struct Bar {\n"
@@ -4382,7 +4380,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" f(bar);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:11]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:11]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("class Foo {};\n" // #10750
"struct Bar {\n"
@@ -4398,7 +4396,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" f(bar);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:10]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str());
check("void f(std::string_view text);\n" // #11508
"void g() {\n"
@@ -4408,7 +4406,7 @@ class TestAutoVariables : public TestFixture {
"void f(std::string_view text) {"
" g(text.data());\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(std::span data);\n" // #11508
"void g() {\n"
@@ -4418,7 +4416,7 @@ class TestAutoVariables : public TestFixture {
"void f(std::span data) {"
" g(data.begin());\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -4431,7 +4429,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" *p = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout_str());
// FP: don't warn in subfunction
check("void f(struct KEY *key) {\n"
@@ -4448,7 +4446,7 @@ class TestAutoVariables : public TestFixture {
" }\n"
" f(tmp);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Don't warn about references (#6399)
check("void f() {\n"
@@ -4460,7 +4458,7 @@ class TestAutoVariables : public TestFixture {
" if (former_hover != pitem)\n"
" dosth();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" wxAuiToolBarItem* former_hover = NULL;\n"
@@ -4473,7 +4471,7 @@ class TestAutoVariables : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:5] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'item' that is out of scope.\n",
- errout.str());
+ errout_str());
// #6575
check("void trp_deliver_signal() {\n"
@@ -4484,7 +4482,7 @@ class TestAutoVariables : public TestFixture {
" EventReport * rep = &repData;\n"
" rep->setEventType(NDB_LE_Connected);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #8785
check("int f(bool a, bool b) {\n"
@@ -4497,7 +4495,7 @@ class TestAutoVariables : public TestFixture {
" return *iPtr;\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:8]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:8]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout_str());
// #11753
check("int main(int argc, const char *argv[]) {\n"
@@ -4508,13 +4506,13 @@ class TestAutoVariables : public TestFixture {
" }\n"
" std::cout << s;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'buff' that is out of scope.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'buff' that is out of scope.\n", errout_str());
check("char* f(char* dst) {\n"
" const char* src = \"abc\";\n"
" return strcpy(dst, src);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void splitNamespaceAuto() { // #10473
@@ -4526,7 +4524,7 @@ class TestAutoVariables : public TestFixture {
"{\n"
" int i;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
};
diff --git a/test/testbool.cpp b/test/testbool.cpp
index 6f5402171dd..b8fb0955881 100644
--- a/test/testbool.cpp
+++ b/test/testbool.cpp
@@ -78,9 +78,6 @@ class TestBool : public TestFixture {
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
- // Clear the error buffer..
- errout.str("");
-
// Tokenize..
Tokenizer tokenizer(settings, this);
std::istringstream istr(code);
@@ -95,28 +92,28 @@ class TestBool : public TestFixture {
check("void foo(bool *p) {\n"
" p = false;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout_str());
check("void foo(bool *p) {\n"
" p = (x[rSize];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// ticket #6588 (c mode)
check("struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\n"
@@ -151,7 +148,7 @@ class TestBool : public TestFixture {
" ctx->q_intra_matrix :"
" ctx->q_chroma_intra_matrix;\n"
"}", "test.c");
- ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout.str());
+ ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout_str());
// ticket #6588 (c++ mode)
check("struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\n"
@@ -161,7 +158,7 @@ class TestBool : public TestFixture {
" ctx->q_intra_matrix :"
" ctx->q_chroma_intra_matrix;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Boolean value assigned to pointer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Boolean value assigned to pointer.\n", errout_str());
// ticket #6665
check("void pivot_big(char *first, int compare(const void *, const void *)) {\n"
@@ -170,37 +167,37 @@ class TestBool : public TestFixture {
" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\n"
" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n"
"}", "test.c");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #7381
check("void foo(bool *p, bool b) {\n"
" p = b;\n"
" p = &b;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout_str());
}
void assignBoolToFloat() {
check("void foo1() {\n"
" double d = false;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout_str());
check("void foo2() {\n"
" float d = true;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout_str());
check("void foo3() {\n"
" long double d = (2>1);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout_str());
// stability - don't crash:
check("void foo4() {\n"
" unknown = false;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S {\n"
" float p;\n"
@@ -209,7 +206,7 @@ class TestBool : public TestFixture {
" S s = {0};\n"
" s.p = true;\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout_str());
check("struct S {\n"
" float* p[1];\n"
@@ -218,7 +215,7 @@ class TestBool : public TestFixture {
" S s = {0};\n"
" *s.p[0] = true;\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout_str());
}
void comparisonOfBoolExpressionWithInt1() {
@@ -226,44 +223,44 @@ class TestBool : public TestFixture {
" if ((x && 0x0f)==6)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(int x) {\n"
" if ((x && 0x0f)==0)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if ((x || 0x0f)==6)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(int x) {\n"
" if ((x || 0x0f)==0)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if ((x & 0x0f)==6)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if ((x | 0x0f)==6)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if ((5 && x)==3)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(int x) {\n"
" if ((5 && x)==3 || (8 && x)==9)\n"
@@ -272,137 +269,137 @@ class TestBool : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n"
"[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", // duplicate
- errout.str());
+ errout_str());
check("void f(int x) {\n"
" if ((5 && x)!=3)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(int x) {\n"
" if ((5 && x) > 3)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(int x) {\n"
" if ((5 && x) > 0)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if ((5 && x) < 0)\n"
" a++;\n"
"}"
);
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str());
check("void f(int x) {\n"
" if ((5 && x) < 1)\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if ((5 && x) > 1)\n"
" a++;\n"
"}"
);
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str());
check("void f(int x) {\n"
" if (0 < (5 && x))\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if (0 > (5 && x))\n"
" a++;\n"
"}"
);
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str());
check("void f(int x) {\n"
" if (1 > (5 && x))\n"
" a++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x) {\n"
" if (1 < (5 && x))\n"
" a++;\n"
"}"
);
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str());
check("void f(bool x ) {\n"
" if ( x > false )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( false < x )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( x < false )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( false > x )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( x >= false )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( false >= x )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( x <= false )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(bool x ) {\n"
" if ( false <= x )\n"
" a++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("typedef int (*func)(bool invert);\n"
"void x(int, func f);\n"
"void foo(int error) {\n"
" if (error == ABC) { }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() { return !a+b1){} }");
- ASSERT_EQUALS("",errout.str());
+ ASSERT_EQUALS("",errout_str());
check("void f(int a, int b, int c) { if (a != !b || c) {} }");
- ASSERT_EQUALS("",errout.str());
+ ASSERT_EQUALS("",errout_str());
check("void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }");
- ASSERT_EQUALS("",errout.str());
+ ASSERT_EQUALS("",errout_str());
check("void f(int a, int b, int c) { if (1 < !(a+b)) {} }");
- ASSERT_EQUALS("[test.cpp:1]: (warning) Comparison of a boolean expression with an integer.\n",errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (warning) Comparison of a boolean expression with an integer.\n",errout_str());
}
void comparisonOfBoolExpressionWithInt3() {
check("int f(int x) {\n"
" return t<0>() && x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolExpressionWithInt4() {
@@ -497,48 +494,48 @@ class TestBool : public TestFixture {
check("void f() {\n"
" for(int i = 4; i > -1 < 5 ; --i) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(int a, int b, int c) {\n"
" return (a > b) < c;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a, int b, int c) {\n"
" return x(a > b) < c;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a, int b, int c) {\n"
" return a > b == c;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// templates
check("struct Tokenizer { TokenList list; };\n"
"void Tokenizer::f() {\n"
" std::list locationList;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #5063 - or
check("void f() {\n"
" return a > b or c < d;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() {\n"
" return (a < b) != 0U;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() {\n"
" return (a < b) != 0x0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() {\n"
" return (a < b) != 42U;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
}
void checkComparisonOfFuncReturningBool1() {
@@ -562,7 +559,7 @@ class TestBool : public TestFixture {
" else\n"
" return true;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void checkComparisonOfFuncReturningBool2() {
@@ -588,7 +585,7 @@ class TestBool : public TestFixture {
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n"
- "[test.cpp:11]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ "[test.cpp:11]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void checkComparisonOfFuncReturningBool3() {
@@ -600,7 +597,7 @@ class TestBool : public TestFixture {
"}\n"
"bool compare(int temp);");
ASSERT_EQUALS("[test.cpp:3]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n"
- "[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ "[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void checkComparisonOfFuncReturningBool4() {
@@ -625,7 +622,7 @@ class TestBool : public TestFixture {
" else\n"
" return false;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void checkComparisonOfFuncReturningBool5() {
@@ -649,7 +646,7 @@ class TestBool : public TestFixture {
" else\n"
" return true;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void checkComparisonOfFuncReturningBool6() {
@@ -663,7 +660,7 @@ class TestBool : public TestFixture {
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("namespace Foo {\n"
" bool compare1(int temp);\n"
@@ -675,7 +672,7 @@ class TestBool : public TestFixture {
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int compare1(int temp);\n"
"namespace Foo {\n"
@@ -687,7 +684,7 @@ class TestBool : public TestFixture {
" }\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
check("int compare1(int temp);\n"
"namespace Foo {\n"
@@ -699,7 +696,7 @@ class TestBool : public TestFixture {
" }\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool compare1(int temp);\n"
"void f(){\n"
@@ -708,7 +705,7 @@ class TestBool : public TestFixture {
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void checkComparisonOfFuncReturningBool7() { // #7197
@@ -726,7 +723,7 @@ class TestBool : public TestFixture {
"[test.cpp:7]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n"
"[test.cpp:8]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n"
"[test.cpp:9]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n",
- errout.str());
+ errout_str());
}
void checkComparisonOfFuncReturningBool8() { // #4103
@@ -738,7 +735,7 @@ class TestBool : public TestFixture {
" ;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
// op: <
check("int main(void){\n"
" bool a = true;\n"
@@ -747,7 +744,7 @@ class TestBool : public TestFixture {
" ;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
// op: >=
check("int main(void){\n"
" bool a = true;\n"
@@ -756,7 +753,7 @@ class TestBool : public TestFixture {
" ;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
// op: <=
check("int main(void){\n"
" bool a = true;\n"
@@ -765,7 +762,7 @@ class TestBool : public TestFixture {
" ;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798
@@ -777,7 +774,7 @@ class TestBool : public TestFixture {
" return 1;\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void checkComparisonOfBoolWithBool() {
@@ -804,133 +801,133 @@ class TestBool : public TestFixture {
" return false;\n"
"}\n";
check(code);
- ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str());
}
void bitwiseOnBoolean() { // 3062
check("void f(_Bool a, _Bool b) {\n"
" if(a & b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("void f(_Bool a, _Bool b) {\n"
" if(a | b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("void f(bool a, bool b) {\n"
" if(a & !b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("void f(bool a, bool b) {\n"
" if(a | !b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("bool a, b;\n"
"void f() {\n"
" if(a & b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("bool a, b;\n"
"void f() {\n"
" if(a & !b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("bool a, b;\n"
"void f() {\n"
" if(a | b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("bool a, b;\n"
"void f() {\n"
" if(a | !b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("void f(bool a, int b) {\n"
" if(a & b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("void f(int a, bool b) {\n"
" if(a & b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("void f(int a, int b) {\n"
" if((a > 0) & (b < 0)) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'?\n", errout_str());
check("void f(bool a, int b) {\n"
" if(a | b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("void f(int a, bool b) {\n"
" if(a | b) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("int f(bool a, int b) {\n"
" return a | b;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(bool a, int b) {\n"
" return a | b;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("void f(int a, int b) {\n"
" if(a & b) {}\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool b) {\n"
" foo(bar, &b);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool b) {\n" // #9405
" class C { void foo(bool &b) {} };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f();\n"
"bool g() {\n"
" return f() | f();\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("uint8 outcode(float p) {\n"
" float d = 0.;\n"
" return ((p - xm >= d) << 1) | (x - p > d);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int g();\n" // #10655
"void f(bool b) {\n"
" if (g() | b) {}\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("int g();\n"
"void f(bool b) {\n"
" if (b | g()) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int g();\n"
"bool f(bool b, bool c) {\n"
" return b | g() | c;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'?\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'?\n", errout_str());
check("void f(int i) {\n" // #4233
" bool b = true, c = false;\n"
@@ -940,20 +937,20 @@ class TestBool : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation.\n"
"[test.cpp:4]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation.\n",
- errout.str());
+ errout_str());
check("void f(int i, int j, bool b) {\n"
" i &= b;\n"
" j |= b;\n"
" if (b || c) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(bool b, int i) {\n"
" b &= (i == 5);\n"
" return b;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S { bool b{}; };\n" // #12455
"void f(const std::unordered_map m) {\n"
@@ -963,33 +960,33 @@ class TestBool : public TestFixture {
" (void)s.b;\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void incrementBoolean() {
check("bool bValue = true;\n"
"void f() { bValue++; }");
- ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str());
check("void f(bool test){\n"
" test++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str());
check("void f(bool* test){\n"
" (*test)++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str());
check("void f(bool* test){\n"
" test[0]++;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str());
check("void f(int test){\n"
" test++;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt1() {
@@ -998,51 +995,51 @@ class TestBool : public TestFixture {
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(bool x) {\n"
" if (10 >= x) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(bool x) {\n"
" if (x != 0) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool x) {\n" // #3356
" if (x == 1) {\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool x) {\n"
" if (x != 10) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(bool x) {\n"
" if (x == 10) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
check("void f(bool x) {\n"
" if (x == 0) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("DensePropertyMap visited;"); // #4075
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt2() {
@@ -1051,28 +1048,28 @@ class TestBool : public TestFixture {
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int x, bool y) {\n"
" if (x == y) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool x, bool y) {\n"
" if (x == y) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool x, fooClass y) {\n"
" if (x == y) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt3() {
@@ -1081,35 +1078,35 @@ class TestBool : public TestFixture {
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str());
check("void f(int y) {\n"
" if (true == y) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool y) {\n"
" if (y == true) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(bool y) {\n"
" if (false < 5) {\n"
" printf(\"foo\");\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str());
}
void comparisonOfBoolWithInt4() {
check("void f(int x) {\n"
" if (!x == 1) { }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt5() {
@@ -1117,21 +1114,21 @@ class TestBool : public TestFixture {
" bool (SciTEBase::*ischarforsel)(char ch);\n"
" if (visible != GetVisible(index)) { }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool
check("void SetVisible(bool b, int i) {\n"
" if (b == (bool)i) { }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt7() { // #4846 - (!x==true)
check("void f(int x) {\n"
" if (!x == true) { }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt8() { // #9165
@@ -1141,7 +1138,7 @@ class TestBool : public TestFixture {
" if (expectedResult == res)\n"
" throw 2;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int Fun();\n"
"void Test(bool expectedResult) {\n"
@@ -1149,7 +1146,7 @@ class TestBool : public TestFixture {
" if (expectedResult == res)\n"
" throw 2;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool Fun();\n"
"void Test(bool expectedResult) {\n"
@@ -1157,7 +1154,7 @@ class TestBool : public TestFixture {
" if (5 + expectedResult == res)\n"
" throw 2;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int Fun();\n"
"void Test(bool expectedResult) {\n"
@@ -1165,7 +1162,7 @@ class TestBool : public TestFixture {
" if (5 + expectedResult == res)\n"
" throw 2;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int Fun();\n"
"void Test(bool expectedResult) {\n"
@@ -1173,7 +1170,7 @@ class TestBool : public TestFixture {
" if (expectedResult == res + 5)\n"
" throw 2;\n"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
}
void comparisonOfBoolWithInt9() { // #9304
@@ -1184,7 +1181,7 @@ class TestBool : public TestFixture {
" }\n"
" return b;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void comparisonOfBoolWithInt10() { // #10935
@@ -1193,7 +1190,7 @@ class TestBool : public TestFixture {
"void f(bool v) {\n"
" if (v == H) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("namespace N {\n"
" enum class E { H = 2 };\n"
@@ -1201,7 +1198,7 @@ class TestBool : public TestFixture {
"void f(bool v) {\n"
" if (v == N::H) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -1209,76 +1206,76 @@ class TestBool : public TestFixture {
check("void f(char *p) {\n"
" if (p+1){}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str());
check("void f(char *p) {\n"
" do {} while (p+1);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str());
check("void f(char *p) {\n"
" while (p-1) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str());
check("void f(char *p) {\n"
" for (int i = 0; p+1; i++) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str());
check("void f(char *p) {\n"
" if (p && p+1){}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str());
check("void f(char *p) {\n"
" if (p+2 || p) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str());
}
void returnNonBool() {
check("bool f(void) {\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" return 1;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" return 2;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" return -1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" return 1 + 1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" int x = 0;\n"
" return x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" int x = 10;\n"
" return x;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" return 2 < 1;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" int ret = 0;\n"
@@ -1286,7 +1283,7 @@ class TestBool : public TestFixture {
" ret = 1;\n"
" return ret;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" int ret = 0;\n"
@@ -1294,7 +1291,7 @@ class TestBool : public TestFixture {
" ret = 3;\n"
" return ret;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" if (a)\n"
@@ -1302,12 +1299,12 @@ class TestBool : public TestFixture {
" return 4;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n"
- "[test.cpp:4]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ "[test.cpp:4]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" return;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnNonBoolLambda() {
@@ -1315,42 +1312,42 @@ class TestBool : public TestFixture {
" auto x = [](void) { return -1; };\n"
" return false;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" auto x = [](void) { return -1; };\n"
" return 2;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f(void) {\n"
" auto x = [](void) -> int { return -1; };\n"
" return false;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(void) {\n"
" auto x = [](void) -> int { return -1; };\n"
" return 2;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str());
}
void returnNonBoolLogicalOp() {
check("bool f(int x) {\n"
" return x & 0x4;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(int x, int y) {\n"
" return x | y;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f(int x) {\n"
" return (x & 0x2);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void returnNonBoolClass() {
@@ -1358,7 +1355,7 @@ class TestBool : public TestFixture {
" public:\n"
" bool f() { return -1;}\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str());
check("bool f() {\n"
" struct X {\n"
@@ -1367,7 +1364,7 @@ class TestBool : public TestFixture {
" };\n"
" return false;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f() {\n"
" class X {\n"
@@ -1376,7 +1373,7 @@ class TestBool : public TestFixture {
" };\n"
" return false;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool f() {\n"
" class X {\n"
@@ -1386,7 +1383,7 @@ class TestBool : public TestFixture {
" return -1;\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (style) Non-boolean value returned from function returning bool\n"
- "[test.cpp:4]: (style) Non-boolean value returned from function returning bool\n", errout.str());
+ "[test.cpp:4]: (style) Non-boolean value returned from function returning bool\n", errout_str());
}
};
diff --git a/test/testboost.cpp b/test/testboost.cpp
index 702f88c6808..af09069eb70 100644
--- a/test/testboost.cpp
+++ b/test/testboost.cpp
@@ -38,9 +38,6 @@ class TestBoost : public TestFixture {
#define check(code) check_(code, __FILE__, __LINE__)
void check_(const char code[], const char* file, int line) {
- // Clear the error buffer..
- errout.str("");
-
// Tokenize..
Tokenizer tokenizer(settings, this);
std::istringstream istr(code);
@@ -57,7 +54,7 @@ class TestBoost : public TestFixture {
" data.push_back(123);\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout_str());
check("void f() {\n"
" set data;\n"
@@ -65,7 +62,7 @@ class TestBoost : public TestFixture {
" data.insert(123);\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout_str());
check("void f() {\n"
" set data;\n"
@@ -73,7 +70,7 @@ class TestBoost : public TestFixture {
" data.erase(123);\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout_str());
// Check single line usage
check("void f() {\n"
@@ -81,14 +78,14 @@ class TestBoost : public TestFixture {
" BOOST_FOREACH(const int &i, data)\n"
" data.clear();\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) BOOST_FOREACH caches the end() iterator. It's undefined behavior if you modify the container inside.\n", errout_str());
// Container returned as result of a function -> Be quiet
check("void f() {\n"
" BOOST_FOREACH(const int &i, get_data())\n"
" data.insert(i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Break after modification (#4788)
check("void f() {\n"
@@ -98,7 +95,7 @@ class TestBoost : public TestFixture {
" break;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
};
diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp
index b487c39b08c..0160c084942 100644
--- a/test/testbufferoverrun.cpp
+++ b/test/testbufferoverrun.cpp
@@ -42,9 +42,6 @@ class TestBufferOverrun : public TestFixture {
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
- // Clear the error buffer..
- errout.str("");
-
const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();
// Tokenize..
@@ -61,9 +58,6 @@ class TestBufferOverrun : public TestFixture {
std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
- // Clear the error buffer..
- errout.str("");
-
// Check for buffer overruns..
runChecks(tokenizer, this);
}
@@ -71,9 +65,6 @@ class TestBufferOverrun : public TestFixture {
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
void checkP_(const char* file, int line, const char code[], const char* filename = "test.cpp")
{
- // Clear the error buffer..
- errout.str("");
-
const Settings settings = settingsBuilder(settings0).severity(Severity::performance)
.c(Standards::CLatest).cpp(Standards::CPPLatest).certainty(Certainty::inconclusive).build();
@@ -325,7 +316,7 @@ class TestBufferOverrun : public TestFixture {
" char str[50];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -347,7 +338,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" strcpy(buf, str);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -358,7 +349,7 @@ class TestBufferOverrun : public TestFixture {
" char data[1];\n"
" return abc.data[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -368,7 +359,7 @@ class TestBufferOverrun : public TestFixture {
" char data[100];\n"
" const char *p = data + 100;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void sizeof3() {
@@ -380,7 +371,7 @@ class TestBufferOverrun : public TestFixture {
" struct group *gr;\n"
" snprintf(group, 32, \"%u\", gr->gr_gid);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_1() {
@@ -390,14 +381,14 @@ class TestBufferOverrun : public TestFixture {
" str[15] = 0;\n"
" str[16] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout_str());
check("char f()\n"
"{\n"
" char str[16] = {0};\n"
" return str[16];\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout_str());
// test stack array
check("int f()\n"
@@ -407,7 +398,7 @@ class TestBufferOverrun : public TestFixture {
" y = x[ 4 ];\n"
" return y;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'x[3]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'x[3]' accessed at index 4, which is out of bounds.\n", errout_str());
check("int f()\n"
"{\n"
@@ -416,15 +407,15 @@ class TestBufferOverrun : public TestFixture {
" y = x[ 2 ];\n"
" return y;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int x[5] = {0};\n"
"int a = x[10];");
- ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout_str());
check("int x[5] = {0};\n"
"int a = (x)[10];");
- ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout_str());
}
@@ -435,21 +426,21 @@ class TestBufferOverrun : public TestFixture {
" str[i] = 0;\n"
"}\n"
"void b() { a(16); }");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout_str());
}
void array_index_4() {
check("char c = \"abc\"[4];");
- ASSERT_EQUALS("[test.cpp:1]: (error) Array '\"abc\"[4]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Array '\"abc\"[4]' accessed at index 4, which is out of bounds.\n", errout_str());
check("p = &\"abc\"[4];");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("char c = \"\\0abc\"[2];");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("char c = L\"abc\"[4];");
- ASSERT_EQUALS("[test.cpp:1]: (error) Array 'L\"abc\"[4]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Array 'L\"abc\"[4]' accessed at index 4, which is out of bounds.\n", errout_str());
}
void array_index_3() {
@@ -460,7 +451,7 @@ class TestBufferOverrun : public TestFixture {
" for (i = 0; i < 100; i++)\n"
" sum += val[i];\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -469,7 +460,7 @@ class TestBufferOverrun : public TestFixture {
" for (i = 1; i < 100; i++)\n"
" sum += val[i];\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout_str());
check("void f(int a)\n"
"{\n"
@@ -478,7 +469,7 @@ class TestBufferOverrun : public TestFixture {
" for (i = a; i < 100; i++)\n"
" sum += val[i];\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout_str());
check("typedef struct g g2[3];\n"
"void foo(char *a)\n"
@@ -488,21 +479,21 @@ class TestBufferOverrun : public TestFixture {
" a[i]=0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(int argc)\n"
"{\n"
" char a[2];\n"
" for (int i = 4; i < argc; i++){}\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(int a[10]) {\n"
" for (int i=0;i<50;++i) {\n"
" a[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index 49, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index 49, which is out of bounds.\n", errout_str());
}
void array_index_6() {
@@ -516,7 +507,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC abc;\n"
" abc.str[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:9]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("struct ABC\n"
"{\n"
@@ -528,7 +519,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC abc;\n"
" return abc.str[10];\n"
"}");
- ASSERT_EQUALS("[test.cpp:9]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout_str());
// This is not out of bounds because it is a variable length array
check("struct ABC\n"
@@ -541,7 +532,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(struct ABC) + 10);\n"
" x->str[1] = 0;"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// This is not out of bounds because it is not a variable length array
check("struct ABC\n"
@@ -555,7 +546,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(struct ABC) + 10);\n"
" x->str[1] = 0;"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
// This is not out of bounds because it is a variable length array
// and the index is within the memory allocated.
@@ -570,7 +561,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(struct ABC) + 10);\n"
" x->str[10] = 0;"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// This is out of bounds because it is outside the memory allocated.
/** @todo this doesn't work because of a bug in sizeof(struct) */
@@ -584,7 +575,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(struct ABC) + 10);\n"
" x->str[11] = 0;"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Array 'str[1]' accessed at index 11, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Array 'str[1]' accessed at index 11, which is out of bounds.\n", "", errout_str());
// This is out of bounds if 'sizeof(ABC)' is 1 (No padding)
check("struct ABC\n"
@@ -597,7 +588,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(ABC) + 10);\n"
" x->str[11] = 0;"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
// This is out of bounds because it is outside the memory allocated
/** @todo this doesn't work because of a bug in sizeof(struct) */
@@ -611,7 +602,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(struct ABC));\n"
" x->str[1] = 0;"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Array 'str[1]' accessed at index 1, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Array 'str[1]' accessed at index 1, which is out of bounds.\n", "", errout_str());
// This is out of bounds because it is outside the memory allocated
// But only if 'sizeof(ABC)' is 1 (No padding)
@@ -625,7 +616,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC* x = malloc(sizeof(ABC));\n"
" x->str[1] = 0;"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
// This is out of bounds because it is not a variable array
check("struct ABC\n"
@@ -638,7 +629,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC x;\n"
" x.str[1] = 0;"
"}");
- ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds.\n", errout_str());
check("struct foo\n"
"{\n"
@@ -651,19 +642,19 @@ class TestBufferOverrun : public TestFixture {
" for ( unsigned int i = 0; i < 64; ++i )\n"
" f.str[i] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:10]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds.\n", errout_str());
check("struct AB { char a[NUM]; char b[NUM]; }\n"
"void f(struct AB *ab) {\n"
" ab->a[0] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("union { char a[1]; int b; } ab;\n"
"void f() {\n"
" ab.a[2] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds.\n", errout_str());
}
@@ -677,7 +668,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" abc->str[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_11() {
@@ -696,7 +687,7 @@ class TestBufferOverrun : public TestFixture {
" abc->str[10] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_12() {
@@ -711,7 +702,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" str[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("class Fred\n"
"{\n"
@@ -724,7 +715,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" return str[10];\n"
"}");
- ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_13() {
@@ -737,7 +728,7 @@ class TestBufferOverrun : public TestFixture {
" int x = buf[i];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_14() {
@@ -747,7 +738,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 10; i++)\n"
" a[i+10] = i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout_str());
}
void array_index_15() {
@@ -757,7 +748,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 10; i++)\n"
" a[10+i] = i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout_str());
}
void array_index_16() {
@@ -767,7 +758,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 10; i++)\n"
" a[i+1] = i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_17() {
@@ -777,7 +768,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 10; i++)\n"
" a[i*2] = i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 18, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 18, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -785,7 +776,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 12; i+=6)\n"
" a[i+5] = i;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -793,21 +784,21 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 12; i+=6)\n"
" a[i+6] = i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[12]' accessed at index 12, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[12]' accessed at index 12, which is out of bounds.\n", errout_str());
check("void f() {\n" // #4398
" int a[2];\n"
" for (int i = 0; i < 4; i+=2)\n"
" a[i] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout_str());
check("void f() {\n" // #4398
" int a[2];\n"
" for (int i = 0; i < 4; i+=2)\n"
" do_stuff(a+i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_18() {
@@ -820,7 +811,7 @@ class TestBufferOverrun : public TestFixture {
" i+=1;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -831,7 +822,7 @@ class TestBufferOverrun : public TestFixture {
" i++;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -842,7 +833,7 @@ class TestBufferOverrun : public TestFixture {
" ++i;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -853,7 +844,7 @@ class TestBufferOverrun : public TestFixture {
" i=4;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -864,7 +855,7 @@ class TestBufferOverrun : public TestFixture {
" i+=1;\n"
" }\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", "", errout_str());
}
void array_index_19() {
@@ -874,7 +865,7 @@ class TestBufferOverrun : public TestFixture {
" char a[2];\n"
" char *end = &(a[2]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Getting more than one past the end is not legal
check("void f()\n"
@@ -882,7 +873,7 @@ class TestBufferOverrun : public TestFixture {
" char a[2];\n"
" char *end = &(a[3]);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 3, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 3, which is out of bounds.\n", errout_str());
}
void array_index_20() {
@@ -893,7 +884,7 @@ class TestBufferOverrun : public TestFixture {
" for ( int i = 0; i < 9; i++ )\n"
" b[i] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_21() {
@@ -907,7 +898,7 @@ class TestBufferOverrun : public TestFixture {
" int b = indices[j];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_22() {
@@ -915,7 +906,7 @@ class TestBufferOverrun : public TestFixture {
" size_t indices[2];\n"
" int b = indices[2];\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds.\n", errout_str());
}
void array_index_23() {
@@ -924,7 +915,7 @@ class TestBufferOverrun : public TestFixture {
" char c[10];\n"
" c[1<<23]='a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds.\n", errout_str());
}
void array_index_24() {
@@ -936,7 +927,7 @@ class TestBufferOverrun : public TestFixture {
" a[" + charMaxPlusOne + "] = 0;\n" // 128/256 > CHAR_MAX
"}\n").c_str());
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index -1, which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index " + charMaxPlusOne + ", which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index " + charMaxPlusOne + ", which is out of bounds.\n", errout_str());
check("void f(signed char n) {\n"
" int a[n];\n" // n <= SCHAR_MAX
@@ -944,7 +935,7 @@ class TestBufferOverrun : public TestFixture {
" a[128] = 0;\n" // 128 > SCHAR_MAX
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[128]' accessed at index -1, which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'a[128]' accessed at index 128, which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'a[128]' accessed at index 128, which is out of bounds.\n", errout_str());
check("void f(unsigned char n) {\n"
" int a[n];\n" // n <= UCHAR_MAX
@@ -952,7 +943,7 @@ class TestBufferOverrun : public TestFixture {
" a[256] = 0;\n" // 256 > UCHAR_MAX
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[256]' accessed at index -1, which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'a[256]' accessed at index 256, which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'a[256]' accessed at index 256, which is out of bounds.\n", errout_str());
check("void f(short n) {\n"
" int a[n];\n" // n <= SHRT_MAX
@@ -960,7 +951,7 @@ class TestBufferOverrun : public TestFixture {
" a[32768] = 0;\n" // 32768 > SHRT_MAX
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout_str());
check("void f(unsigned short n) {\n"
" int a[n];\n" // n <= USHRT_MAX
@@ -968,7 +959,7 @@ class TestBufferOverrun : public TestFixture {
" a[65536] = 0;\n" // 65536 > USHRT_MAX
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds.\n", errout_str());
check("void f(signed short n) {\n"
" int a[n];\n" // n <= SHRT_MAX
@@ -976,25 +967,25 @@ class TestBufferOverrun : public TestFixture {
" a[32768] = 0;\n" // 32768 > SHRT_MAX
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout_str());
check("void f(int n) {\n"
" int a[n];\n" // n <= INT_MAX
" a[-1] = 0;\n" // negative index
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds.\n", errout_str());
check("void f(unsigned int n) {\n"
" int a[n];\n" // n <= UINT_MAX
" a[-1] = 0;\n" // negative index
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds.\n", errout_str());
check("void f(signed int n) {\n"
" int a[n];\n" // n <= INT_MAX
" a[-1] = 0;\n" // negative index
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds.\n", errout_str());
}
void array_index_25() { // #1536
@@ -1002,7 +993,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" long l[SOME_SIZE];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_26() {
@@ -1012,7 +1003,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 3; 0 <= i; i--)\n"
" a[i] = i;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[3]' accessed at index 3, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[3]' accessed at index 3, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -1020,7 +1011,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 3; 0 <= i; i--)\n"
" a[i] = i;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_27() {
@@ -1030,7 +1021,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 10; i++)\n"
" a[i-1] = a[i];\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout_str());
}
void array_index_28() {
@@ -1041,7 +1032,7 @@ class TestBufferOverrun : public TestFixture {
" int *ip = i + 1;\n"
" ip[-10] = 1;\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds.\n", "", errout_str());
}
void array_index_29() {
@@ -1053,7 +1044,7 @@ class TestBufferOverrun : public TestFixture {
" int *ii = i + -5;"
" ii[10] = 0;"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array ii[10] out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array ii[10] out of bounds.\n", "", errout_str());
}
void array_index_30() {
@@ -1063,7 +1054,7 @@ class TestBufferOverrun : public TestFixture {
" UINT8 x[2];\n"
" x[5] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[2]' accessed at index 5, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[2]' accessed at index 5, which is out of bounds.\n", errout_str());
}
void array_index_31() {
@@ -1080,7 +1071,7 @@ class TestBufferOverrun : public TestFixture {
" struct s1 obj;\n"
" x(obj.delay, 123);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct s1 {\n"
" unknown_type_t delay[3];\n"
@@ -1096,7 +1087,7 @@ class TestBufferOverrun : public TestFixture {
"}");
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\n",
"",
- errout.str());
+ errout_str());
check("struct s1 {\n"
" float a[0];\n"
@@ -1105,7 +1096,7 @@ class TestBufferOverrun : public TestFixture {
"void f() {\n"
" struct s1 *obj;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_32() {
@@ -1119,14 +1110,14 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" int m_x[1];\n"
"};");
- ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds.\n", errout_str());
}
void array_index_33() {
check("void foo(char bar[][4]) {\n"
" baz(bar[5]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_34() { // ticket #3063
@@ -1136,7 +1127,7 @@ class TestBufferOverrun : public TestFixture {
" y[0][0][2] = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds.\n"
- "[test.cpp:4]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds.\n", errout.str());
+ "[test.cpp:4]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds.\n", errout_str());
check("struct TEST\n"
"{\n"
@@ -1160,7 +1151,7 @@ class TestBufferOverrun : public TestFixture {
"[test.cpp:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds.\n"
"[test.cpp:14]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds.\n"
"[test.cpp:15]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[10][2], which is out of bounds.\n"
- "[test.cpp:16]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds.\n", errout.str());
+ "[test.cpp:16]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds.\n", errout_str());
check("struct TEST\n"
"{\n"
@@ -1179,7 +1170,7 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("[test.cpp:8]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds.\n"
"[test.cpp:9]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds.\n"
"[test.cpp:12]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds.\n"
- "[test.cpp:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds.\n", errout.str());
+ "[test.cpp:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds.\n", errout_str());
}
void array_index_35() { // ticket #2889
@@ -1187,21 +1178,21 @@ class TestBufferOverrun : public TestFixture {
" struct Struct { unsigned m_Var[1]; } s;\n"
" s.m_Var[1] = 1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds.\n", errout_str());
check("struct Struct { unsigned m_Var[1]; };\n"
"void f() {\n"
" struct Struct s;\n"
" s.m_Var[1] = 1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds.\n", errout_str());
check("struct Struct { unsigned m_Var[1]; };\n"
"void f() {\n"
" struct Struct * s = calloc(40);\n"
" s->m_Var[1] = 1;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_36() { // ticket #2960
@@ -1214,7 +1205,7 @@ class TestBufferOverrun : public TestFixture {
" m_b[2] = rhs.m_b[2];\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds.\n"
- "[test.cpp:7]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds.\n", errout.str());
+ "[test.cpp:7]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds.\n", errout_str());
}
void array_index_37() {
@@ -1225,7 +1216,7 @@ class TestBufferOverrun : public TestFixture {
" i;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_38() { //ticket #3273
@@ -1244,7 +1235,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_39() { // ticket 3387
@@ -1253,7 +1244,7 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" a[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_40() {
@@ -1262,7 +1253,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 10; ++i)\n"
" f2(&a[i + 1]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_41() {
@@ -1275,7 +1266,7 @@ class TestBufferOverrun : public TestFixture {
"void b() {\n"
" struct Fred { char data[3]; } fred;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void a() {\n"
" struct Fred { char data[6]; } fred;\n"
@@ -1286,7 +1277,7 @@ class TestBufferOverrun : public TestFixture {
" struct Fred { char data[3]; } fred;\n"
" fred.data[4] = 0;\n" // <- error
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds.\n", errout_str());
}
void array_index_42() { // ticket #3569
@@ -1297,7 +1288,7 @@ class TestBufferOverrun : public TestFixture {
" p[10] = 7;\n"
" free(p);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -1305,7 +1296,7 @@ class TestBufferOverrun : public TestFixture {
" p[10] = 7;\n"
" free(p);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -1314,7 +1305,7 @@ class TestBufferOverrun : public TestFixture {
" p[9] = 9;\n"
" free(p);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -1323,7 +1314,7 @@ class TestBufferOverrun : public TestFixture {
" p[9] = 9;\n"
" delete [] p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -1332,7 +1323,7 @@ class TestBufferOverrun : public TestFixture {
" p[9] = 9;\n"
" delete [] p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -1347,7 +1338,7 @@ class TestBufferOverrun : public TestFixture {
" p[9] = 9;\n"
" delete [] p;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_43() { // #3838
@@ -1364,7 +1355,7 @@ class TestBufferOverrun : public TestFixture {
" y = var[ 0 ].arr[ 3 ];\n" // <-- array access out of bounds
" return y;\n"
"}");
- ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds.\n", errout_str());
check("int f( )\n"
"{\n"
@@ -1378,7 +1369,7 @@ class TestBufferOverrun : public TestFixture {
" y = var[ 0 ].arr[ 2 ];\n"
" return y;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f( ){\n"
@@ -1395,7 +1386,7 @@ class TestBufferOverrun : public TestFixture {
"return y;\n"
"}");
ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n"
- "[test.cpp:11]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n", errout.str());
+ "[test.cpp:11]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n", errout_str());
check("void f( ) {\n"
@@ -1408,7 +1399,7 @@ class TestBufferOverrun : public TestFixture {
"var[0].var[ 2 ] = 2;\n"
"var[0].var[ 4 ] = 4;\n" // <-- array access out of bounds
"}");
- ASSERT_EQUALS("[test.cpp:9]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds.\n", errout_str());
check("void f( ) {\n"
"struct S{\n"
@@ -1419,7 +1410,7 @@ class TestBufferOverrun : public TestFixture {
"var[0].var[ 1 ] = 1;\n"
"var[0].var[ 2 ] = 2;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// avoid FPs (modified examples taken from #3838)
check("struct AB { int a[10]; int b[10]; };\n"
@@ -1428,7 +1419,7 @@ class TestBufferOverrun : public TestFixture {
" int * p = &ab.a[10];\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct AB { int a[10]; int b[10]; };\n"
"int main() {\n"
@@ -1436,7 +1427,7 @@ class TestBufferOverrun : public TestFixture {
" int * p = &ab[0].a[10];\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct AB { int a[10]; int b[10]; };\n"
"int main() {\n"
@@ -1444,7 +1435,7 @@ class TestBufferOverrun : public TestFixture {
" int * p = &ab[10].a[0];\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_44() { // #3979 (false positive)
@@ -1458,7 +1449,7 @@ class TestBufferOverrun : public TestFixture {
" buf[i] = 1;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -1468,7 +1459,7 @@ class TestBufferOverrun : public TestFixture {
" buf[i] = 2.;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_45() { // #4207 - handling of function with variable number of parameters / unnamed arguments
@@ -1481,7 +1472,7 @@ class TestBufferOverrun : public TestFixture {
" CHAR buffer[1024];\n"
" f(\"%s\", buffer);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Unnamed argument
check("void f(char *) {\n"
@@ -1491,7 +1482,7 @@ class TestBufferOverrun : public TestFixture {
" char buffer[1024];\n"
" f(buffer);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// Two statement for-loop
@@ -1503,7 +1494,7 @@ class TestBufferOverrun : public TestFixture {
" printf(\"files(%i): %s\", 3-i, buffer[3-i]);\n"
" }\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 'buffer[3]' accessed at index 3, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 'buffer[3]' accessed at index 3, which is out of bounds.\n", "", errout_str());
check("void f() {\n"
" int buffer[9];\n"
@@ -1512,7 +1503,7 @@ class TestBufferOverrun : public TestFixture {
" buffer[i] = i;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds.\n", errout_str());
// Correct access limits -> i from 9 to 0
check("void f() {\n"
@@ -1521,7 +1512,7 @@ class TestBufferOverrun : public TestFixture {
" buffer[i] = i;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_47() {
@@ -1531,7 +1522,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 2; i < 0; i++)\n"
" s[i] = 5;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_48() {
@@ -1544,7 +1535,7 @@ class TestBufferOverrun : public TestFixture {
" array[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'array[4]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'array[4]' accessed at index 4, which is out of bounds.\n", errout_str());
check("void test(void)\n"
"{\n"
@@ -1554,7 +1545,7 @@ class TestBufferOverrun : public TestFixture {
" array[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_49() {
@@ -1568,7 +1559,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" arr[k];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_50() {
@@ -1580,7 +1571,7 @@ class TestBufferOverrun : public TestFixture {
" f(\"12345678\");\n"
" f(\"12345\");\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_51() {
@@ -1588,7 +1579,7 @@ class TestBufferOverrun : public TestFixture {
" int k=0, dd, d[1U] = {1};\n"
" for (dd=d[k]; k<10; dd=d[++k]){;}\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'd[1]' accessed at index 1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'd[1]' accessed at index 1, which is out of bounds.\n", errout_str());
}
void array_index_52() {
@@ -1599,7 +1590,7 @@ class TestBufferOverrun : public TestFixture {
" buf[i] = 0;\n"
" return buf[0];\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_53() {
@@ -1611,7 +1602,7 @@ class TestBufferOverrun : public TestFixture {
" for (int j = 0; j < 3; j++)\n"
" M[i][j]=0.0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds.\n", errout_str());
}
void array_index_54() {
@@ -1625,7 +1616,7 @@ class TestBufferOverrun : public TestFixture {
" b[i+1] = 0;\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_55() {
@@ -1642,7 +1633,7 @@ class TestBufferOverrun : public TestFixture {
"void f2() {\n"
" make(\"false\");\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_56() {
@@ -1654,7 +1645,7 @@ class TestBufferOverrun : public TestFixture {
" foo.array[foo.index++] = 1;\n"
" if (foo.index == 1) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_57() {
@@ -1668,7 +1659,7 @@ class TestBufferOverrun : public TestFixture {
" x = c;\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(std::vector& v) {\n"
" int a[3] = { 1, 2, 3 };\n"
@@ -1682,7 +1673,7 @@ class TestBufferOverrun : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:6] -> [test.cpp:5]: (warning) Either the condition 'i==4' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_58()
@@ -1697,7 +1688,7 @@ class TestBufferOverrun : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:6]: (warning) Either the condition 'x<2' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds.\n",
- errout.str());
+ errout_str());
check("void f() {\n" // #2199
" char a[5];\n"
@@ -1715,7 +1706,7 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:5]: (error) Array 'a[5]' accessed at index 8, which is out of bounds.\n"
"[test.cpp:11]: (error) Array 'a[5]' accessed at index 11, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_59() // #10413
@@ -1727,7 +1718,7 @@ class TestBufferOverrun : public TestFixture {
" return 0;\n"
" return a[b];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a, int b) {\n"
" const int S[2] = {};\n"
@@ -1737,13 +1728,13 @@ class TestBufferOverrun : public TestFixture {
" else if (S[b] > S[a]) {}\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int a[2] = {};\n"
"void f(int i) {\n"
" g(i < 0 ? 0 : a[i]);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_60()
@@ -1756,7 +1747,7 @@ class TestBufferOverrun : public TestFixture {
" i = A[i];\n"
" return i;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkP("#define ASSERT(expression, action) if (expression) {action;}\n"
"int array[5];\n"
@@ -1766,7 +1757,7 @@ class TestBufferOverrun : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:5]: (warning) Either the condition 'index>5' is redundant or the array 'array[5]' is accessed at index 5, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_61()
@@ -1779,7 +1770,7 @@ class TestBufferOverrun : public TestFixture {
" return 0; \n"
" return M[i];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S { enum E { e0 }; };\n"
"const S::E M[4] = { S::E:e0, S::E:e0, S::E:e0, S::E:e0 };\n"
@@ -1790,7 +1781,7 @@ class TestBufferOverrun : public TestFixture {
" return 0;\n"
" return M[i]; \n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_62()
@@ -1805,7 +1796,7 @@ class TestBufferOverrun : public TestFixture {
" return buf[0];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_63()
@@ -1817,7 +1808,7 @@ class TestBufferOverrun : public TestFixture {
" if (i >= 0 && i < sizeof(b) / sizeof((b)[0]))\n"
" b[i] = 0;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_64() // #10878
@@ -1830,7 +1821,7 @@ class TestBufferOverrun : public TestFixture {
" Array array = {};\n"
" array.accessArrayRef(10);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("int i = 10;\n"
"struct Array {\n"
@@ -1841,7 +1832,7 @@ class TestBufferOverrun : public TestFixture {
" Array array = {};\n"
" array.accessArrayRef(i);\n"
"}\n");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", "", errout_str());
}
void array_index_65() // #11066
@@ -1853,7 +1844,7 @@ class TestBufferOverrun : public TestFixture {
" for (j = 0; j < 2; j++)\n"
" c[j] = f[P[j] - 1];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_66()
@@ -1867,7 +1858,7 @@ class TestBufferOverrun : public TestFixture {
"}\n");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:5]: (warning) Either the condition 'j>=256' is redundant or the array 'offsets[256]' is accessed at index 256, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_67() {
@@ -1886,7 +1877,7 @@ class TestBufferOverrun : public TestFixture {
" type_cnt++;\n"
" }\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_68() { // #6655
@@ -1899,7 +1890,7 @@ class TestBufferOverrun : public TestFixture {
" f(20);\n"
" return 0;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds.\n", errout_str());
}
// #6370
@@ -1911,7 +1902,7 @@ class TestBufferOverrun : public TestFixture {
" for(int i = 0; i < 4; ++i)\n"
" a[e[i]] = 0;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[4]' accessed at index 30, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[4]' accessed at index 30, which is out of bounds.\n", errout_str());
}
// #11355
@@ -1920,7 +1911,7 @@ class TestBufferOverrun : public TestFixture {
" static const char a[] = ((\"test\"));\n"
" printf(\"%c\", a[5]);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n", errout_str());
}
// #11461
@@ -1933,7 +1924,7 @@ class TestBufferOverrun : public TestFixture {
" int arr[64] = { 0 };\n"
" return arr[Idx];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #11784
@@ -1948,7 +1939,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" return d[3];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #11530
@@ -1959,7 +1950,7 @@ class TestBufferOverrun : public TestFixture {
" std::function a[1] = {};\n"
" a[k++](0);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #11088
@@ -1974,7 +1965,7 @@ class TestBufferOverrun : public TestFixture {
"void bar() {\n"
" foo(\"q\");\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #1644
@@ -1986,7 +1977,7 @@ class TestBufferOverrun : public TestFixture {
" while (i >= 3)\n"
" buf[i--] = 0;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_multidim() {
@@ -1995,87 +1986,87 @@ class TestBufferOverrun : public TestFixture {
" char a[2][2];\n"
" a[1][1] = 'a';\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" char a[2][2][2];\n"
" a[1][1][1] = 'a';\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" char a[2][2];\n"
" a[2][1] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char a[2][2];\n"
" a[1][2] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char a[2][2][2];\n"
" a[2][1][1] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char a[2][2][2];\n"
" a[1][2][1] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char a[2][2][2][2];\n"
" a[1][2][1][1] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char a[2][2][2];\n"
" a[1][1][2] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char a[10][10][10];\n"
" a[2*3][4*3][2] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds.\n", errout_str());
check("void f() {\n"
" char a[10][10][10];\n"
" a[6][40][10] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds.\n", errout_str());
check("void f() {\n"
" char a[1][1][1];\n"
" a[2][2][2] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds.\n", errout_str());
check("void f() {\n"
" char a[6][6][6];\n"
" a[6][6][2] = 'a';\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds.\n", errout_str());
check("void f() {\n"
" int a[2][2];\n"
" p = &a[2][0];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// unknown dim..
check("void f()\n"
@@ -2083,7 +2074,7 @@ class TestBufferOverrun : public TestFixture {
" int a[2][countof(x)] = {{1,2},{3,4}};\n"
" a[0][0] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void draw_quad(float z) {\n"
" int i;\n"
@@ -2105,7 +2096,7 @@ class TestBufferOverrun : public TestFixture {
" vertices[i][1][3] = 5.0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
{
check("int foo() {\n"
@@ -2114,7 +2105,7 @@ class TestBufferOverrun : public TestFixture {
" extern int stuff[A][B];\n"
" return stuff[0][1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// TODO: better handling of VLAs in symboldatabase. should be
// possible to use ValueFlow values.
@@ -2124,7 +2115,7 @@ class TestBufferOverrun : public TestFixture {
" extern int stuff[A][B];\n"
" return stuff[0][1];\n"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
}
}
@@ -2145,7 +2136,7 @@ class TestBufferOverrun : public TestFixture {
" };\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -2163,7 +2154,7 @@ class TestBufferOverrun : public TestFixture {
" };\n"
" }\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Array index out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Array index out of bounds.\n", "", errout_str());
}
void array_index_for_in_for() {
@@ -2175,7 +2166,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_bounds() {
@@ -2187,7 +2178,7 @@ class TestBufferOverrun : public TestFixture {
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds.\n"
"[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_calculation() {
@@ -2199,7 +2190,7 @@ class TestBufferOverrun : public TestFixture {
" data[i/2] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' accessed at index 17, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' accessed at index 17, which is out of bounds.\n", errout_str());
// #2199 - false negative: array out of bounds in loop when there is calculation
check("void f()\n"
@@ -2209,7 +2200,7 @@ class TestBufferOverrun : public TestFixture {
" arr[i + 7] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds.\n", errout_str());
}
void array_index_negative1() {
@@ -2219,21 +2210,21 @@ class TestBufferOverrun : public TestFixture {
" char data[8];\n"
" data[-1] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8]' accessed at index -1, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" char data[8][4];\n"
" data[5][-1] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds.\n", errout_str());
// #1614 - negative index is ok for pointers
check("void foo(char *p)\n"
"{\n"
" p[-1] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo()\n"
"{\n"
@@ -2241,14 +2232,14 @@ class TestBufferOverrun : public TestFixture {
" char *p = s + strlen(s);\n"
" if (p[-1]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// ticket #1850
check("int f(const std::map > &m)\n"
"{\n"
" return m[0][-1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_negative2() { // ticket #3063
@@ -2257,7 +2248,7 @@ class TestBufferOverrun : public TestFixture {
" TEST test;\n"
" test.a[-1] = 3;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds.\n", errout_str());
}
void array_index_negative3() {
@@ -2273,7 +2264,7 @@ class TestBufferOverrun : public TestFixture {
" if( i == 0 )\n"
" return f(i);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_negative4()
@@ -2284,7 +2275,7 @@ class TestBufferOverrun : public TestFixture {
" for(i=0; i <16; ++i){}\n"
" for(; i < 24; ++i){ buf[i] = buf[i-16];}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_negative5() // #10526
@@ -2302,7 +2293,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" return false;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #11349
@@ -2315,7 +2306,7 @@ class TestBufferOverrun : public TestFixture {
" (void)a[k];\n"
" if (i == -3) {}\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #5685
@@ -2327,7 +2318,7 @@ class TestBufferOverrun : public TestFixture {
" for (; i < 5; i++)\n"
" a[i] = 1;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[5]' accessed at index -9, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[5]' accessed at index -9, which is out of bounds.\n", errout_str());
}
// #11651
@@ -2340,7 +2331,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = u, j = sizeof(i); --i >= 0;)\n"
" char c = buf[i];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #8075
@@ -2355,7 +2346,7 @@ class TestBufferOverrun : public TestFixture {
" int a[] = { 1, 2, 3 };\n"
" printf(\"%d\\n\", a[g(4)]);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:8]: (error) Array 'a[3]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Array 'a[3]' accessed at index -1, which is out of bounds.\n", errout_str());
}
// #11844
@@ -2369,7 +2360,7 @@ class TestBufferOverrun : public TestFixture {
" for (int j = m + 1; j <= 4; j++)\n"
" p->a[j-1];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_for_decr() {
@@ -2380,7 +2371,7 @@ class TestBufferOverrun : public TestFixture {
" data[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
@@ -2389,7 +2380,7 @@ class TestBufferOverrun : public TestFixture {
" val[i+1] = val[i];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -2399,7 +2390,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds.\n"
- "[test.cpp:5]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds.\n", errout.str());
+ "[test.cpp:5]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds.\n", errout_str());
}
@@ -2416,7 +2407,7 @@ class TestBufferOverrun : public TestFixture {
" a.data[3] = 0;\n"
" a.b.data[2] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #1586
check("struct A {\n"
@@ -2432,7 +2423,7 @@ class TestBufferOverrun : public TestFixture {
" a.b.data[3] = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:10]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds.\n"
- "[test.cpp:11]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds.\n", errout.str());
+ "[test.cpp:11]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds.\n", errout_str());
}
void array_index_for_andand_oror() { // #3907 - using && or ||
@@ -2445,7 +2436,7 @@ class TestBufferOverrun : public TestFixture {
" data[x] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout_str());
check("void f() {\n"
" char data[2];\n"
@@ -2454,7 +2445,7 @@ class TestBufferOverrun : public TestFixture {
" data[x] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout_str());
check("void f() {\n"
" char data[2];\n"
@@ -2463,7 +2454,7 @@ class TestBufferOverrun : public TestFixture {
" data[x] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void f() {\n"
" char data[2];\n"
@@ -2472,7 +2463,7 @@ class TestBufferOverrun : public TestFixture {
" data[x] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout_str());
check("int f() {\n" // #9126
" int i, c;\n"
@@ -2484,7 +2475,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" return c;\n"
"}", "test.c");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_for_continue() {
@@ -2498,7 +2489,7 @@ class TestBufferOverrun : public TestFixture {
" a[i - 1] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// extracttests.start: int maybe();
check("void f() {\n"
@@ -2510,7 +2501,7 @@ class TestBufferOverrun : public TestFixture {
" a[i - 1] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[2]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[2]' accessed at index -1, which is out of bounds.\n", errout_str());
}
void array_index_for() {
@@ -2523,7 +2514,7 @@ class TestBufferOverrun : public TestFixture {
" a[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout_str());
// Ticket #2385 - No false positive
check("void f() {\n"
@@ -2535,7 +2526,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Ticket #3893 - start value out of bounds
// extracttests.start: int maybe(); int dostuff();
@@ -2545,7 +2536,7 @@ class TestBufferOverrun : public TestFixture {
" a[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str());
// #7686
check("char f() {\n"
@@ -2555,7 +2546,7 @@ class TestBufferOverrun : public TestFixture {
" buf[i] = 0;\n"
" return buf[0];\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void array_index_for_neq() {
@@ -2567,7 +2558,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[5]' accessed at index 9, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
void array_index_for_question() {
@@ -2578,7 +2569,7 @@ class TestBufferOverrun : public TestFixture {
" i == 0 ? 0 : a[i-1];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" int a[10];\n"
@@ -2587,7 +2578,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n",
- errout.str());
+ errout_str());
check("void f() {\n"
" int a[10];\n"
@@ -2596,7 +2587,7 @@ class TestBufferOverrun : public TestFixture {
" a[i-1] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout_str());
}
void array_index_for_varid0() { // #4228: No varid for counter variable
@@ -2604,7 +2595,7 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" for (i=0; i<10; i++);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_vla_for() {
@@ -2615,14 +2606,14 @@ class TestBufferOverrun : public TestFixture {
" a[0] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_extern() {
// Ticket #1684. FP when using 'extern'.
check("extern char arr[15];\n"
"char arr[15] = \"abc\";");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_cast() {
@@ -2636,7 +2627,7 @@ class TestBufferOverrun : public TestFixture {
" int x[2];\n"
" f1(x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Same type => error
check("void f1(const char buf[]) {\n"
@@ -2648,7 +2639,7 @@ class TestBufferOverrun : public TestFixture {
"}");
TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\n",
"",
- errout.str());
+ errout_str());
}
void array_index_string_literal() {
@@ -2656,41 +2647,41 @@ class TestBufferOverrun : public TestFixture {
" const char *str = \"abc\";\n"
" bar(str[10]);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'str[4]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'str[4]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" const char *str = \"abc\";\n"
" bar(str[4]);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout_str());
check("void f()\n"
"{\n"
" const char *str = \"abc\";\n"
" bar(str[3]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
" const char *str = \"a\tc\";\n"
" bar(str[4]);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout_str());
check("void f() {\n" // #6973
" const char *name = \"\";\n"
" if ( name[0] == 'U' ? name[1] : 0) {}\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int main(int argc, char **argv) {\n"
" char str[6] = \"\\0\";\n"
" unsigned short port = 65535;\n"
" snprintf(str, sizeof(str), \"%hu\", port);\n"
"}", settings0, "test.c");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(int x) {\n" // #11020
" const char* p = (x == 0 ? \"12345\" : \"ABC\");\n"
@@ -2699,7 +2690,7 @@ class TestBufferOverrun : public TestFixture {
" s += p[i];\n"
" return s;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_same_struct_and_var_name() {
@@ -2712,7 +2703,7 @@ class TestBufferOverrun : public TestFixture {
" struct tt *tt=x;\n"
" tt->name;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// detect error
check("struct tt {\n"
@@ -2723,7 +2714,7 @@ class TestBufferOverrun : public TestFixture {
" struct tt *tt=x;\n"
" tt->name[22] = 123;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds.\n", errout_str());
}
void array_index_valueflow() {
@@ -2732,7 +2723,7 @@ class TestBufferOverrun : public TestFixture {
" str[i] = 0;\n"
" if (i==10) {}\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds.\n", errout_str());
check("void f(int i) {\n"
" char str[3];\n"
@@ -2741,31 +2732,31 @@ class TestBufferOverrun : public TestFixture {
" case 10: break;\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds.\n", errout_str());
check("void f() {\n"
" char str[3];\n"
" str[((unsigned char)3) - 1] = 0;\n"
"}", "test.cpp");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n" // #5416 FP
" char *str[3];\n"
" do_something(&str[0][5]);\n"
"}", "test.cpp");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class X { static const int x[100]; };\n" // #6070
"const int X::x[100] = {0};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("namespace { class X { static const int x[100]; };\n" // #6232
"const int X::x[100] = {0}; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\n"
"ImageSet *ActorSprite::targetCursorImages[2][10];");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(const std::size_t s) {\n" // #10130
" const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\n"
@@ -2775,7 +2766,7 @@ class TestBufferOverrun : public TestFixture {
" return f(16);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds.\n",
- errout.str());
+ errout_str());
}
@@ -2785,7 +2776,7 @@ class TestBufferOverrun : public TestFixture {
" int *p = a;\n"
" p[20] = 0;\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", "", errout_str());
{
// address of
@@ -2794,14 +2785,14 @@ class TestBufferOverrun : public TestFixture {
" int *p = a;\n"
" p[10] = 0;\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", "", errout_str());
check("void f() {\n"
" int a[10];\n"
" int *p = a;\n"
" dostuff(&p[10]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
check("void f() {\n"
@@ -2809,33 +2800,33 @@ class TestBufferOverrun : public TestFixture {
" int *p = a;\n"
" p[20] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" int a[2];\n"
" char *p = (char *)a;\n" // cast
" p[4] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_function_parameter() {
check("void f(char a[10]) {\n"
" a[20] = 0;\n" // <- cppcheck warn here even though it's not a definite access out of bounds
"}");
- ASSERT_EQUALS("[test.cpp:2]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", errout_str());
check("void f(char a[10]) {\n" // #6353 - reassign 'a'
" a += 4;\n"
" a[-1] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char a[10]) {\n"
" a[0] = 0;\n"
" a[-1] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout_str());
}
void array_index_enum_array() { // #8439
@@ -2844,7 +2835,7 @@ class TestBufferOverrun : public TestFixture {
" E arrE[] = { e1, e2 };\n"
" arrE[sizeof(arrE)] = e1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds.\n", errout_str());
}
void array_index_container() { // #9386
@@ -2852,7 +2843,7 @@ class TestBufferOverrun : public TestFixture {
"void foo(std::array& a) {\n"
" a[2] = 2;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_two_for_loops() {
@@ -2866,7 +2857,7 @@ class TestBufferOverrun : public TestFixture {
" if (i < 50)\n"
" sum -= val[i];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool b();\n"
"void f()\n"
@@ -2880,7 +2871,7 @@ class TestBufferOverrun : public TestFixture {
" break;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("bool b();\n"
"void f()\n"
@@ -2892,7 +2883,7 @@ class TestBufferOverrun : public TestFixture {
" for (; i < 50; i++)\n"
" sum -= val[i];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_new() { // #7690
@@ -2902,7 +2893,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = 0;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void f() {\n"
" int* z = new int(1);\n"
@@ -2910,7 +2901,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = 0;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void f() {\n"
" int* z = new int{};\n"
@@ -2918,7 +2909,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = 0;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void f() {\n"
" int* z = new int[5];\n"
@@ -2926,7 +2917,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = 0;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void g() {\n"
" int* z = new int[5]();\n"
@@ -2934,7 +2925,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = 1;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void h() {\n"
" int** z = new int* [5];\n"
@@ -2942,7 +2933,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = nullptr;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void h() {\n"
" int** z = new int* [5]();\n"
@@ -2950,7 +2941,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = nullptr;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void h() {\n"
" int** z = new int* [5]{};\n"
@@ -2958,7 +2949,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = nullptr;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str());
check("void h() {\n"
" int** z = new int* [5]{ 0 };\n"
@@ -2966,7 +2957,7 @@ class TestBufferOverrun : public TestFixture {
" z[n] = nullptr;\n"
" delete[] z;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str());
}
void buffer_overrun_2_struct() {
@@ -2979,7 +2970,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" strcpy( abc->str, \"abcdef\" );\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc->str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc->str\n", errout_str());
check("struct ABC\n"
"{\n"
@@ -2991,7 +2982,7 @@ class TestBufferOverrun : public TestFixture {
" struct ABC abc;\n"
" strcpy( abc.str, \"abcdef\" );\n"
"}");
- ASSERT_EQUALS("[test.cpp:9]: (error) Buffer is accessed out of bounds: abc.str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9]: (error) Buffer is accessed out of bounds: abc.str\n", errout_str());
check("struct ABC\n"
"{\n"
@@ -3002,7 +2993,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" strcpy( abc.str, \"abcdef\" );\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc.str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc.str\n", errout_str());
check("static void f()\n"
"{\n"
@@ -3012,7 +3003,7 @@ class TestBufferOverrun : public TestFixture {
" } abc;\n"
" strcpy( abc.str, \"abcdef\" );\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: abc.str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: abc.str\n", errout_str());
check("static void f()\n"
"{\n"
@@ -3024,7 +3015,7 @@ class TestBufferOverrun : public TestFixture {
" strcpy( abc->str, \"abcdef\" );\n"
" free(abc);\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc->str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc->str\n", errout_str());
}
@@ -3037,11 +3028,11 @@ class TestBufferOverrun : public TestFixture {
" for (i = 0; i <= 10; ++i)\n"
" a[i] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("struct S { int b; } static e[1];\n" // #11052
"int f() { return e[1].b; }\n");
- ASSERT_EQUALS("[test.cpp:2]: (error) Array 'e[1]' accessed at index 1, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Array 'e[1]' accessed at index 1, which is out of bounds.\n", errout_str());
}
@@ -3052,7 +3043,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 8; ++i)\n"
" p[i] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'p[2]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'p[2]' accessed at index 7, which is out of bounds.\n", errout_str());
// No false positive
check("void foo(int x, int y)\n"
@@ -3061,7 +3052,7 @@ class TestBufferOverrun : public TestFixture {
" const char *s = y + p[1];\n"
" p[1] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// There is no error here
check("void f1(char *s,int size)\n"
@@ -3073,7 +3064,7 @@ class TestBufferOverrun : public TestFixture {
" char s[3];\n"
" f1(s,20);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
check("void f1(char *s,int size)\n"
"{\n"
@@ -3084,7 +3075,7 @@ class TestBufferOverrun : public TestFixture {
" char s[3];\n"
" f1(s,3);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_5() {
@@ -3094,7 +3085,7 @@ class TestBufferOverrun : public TestFixture {
" sprintf(n, \"d\");\n"
" printf(\"hello!\");\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_6() {
@@ -3104,7 +3095,7 @@ class TestBufferOverrun : public TestFixture {
" strcat(n, \"abc\");\n"
" strcat(n, \"def\");\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: n\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: n\n", "", errout_str());
}
void buffer_overrun_7() {
@@ -3114,7 +3105,7 @@ class TestBufferOverrun : public TestFixture {
" char a[2];\n"
" strcpy(a, \"a\\0\");\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_8() {
@@ -3127,7 +3118,7 @@ class TestBufferOverrun : public TestFixture {
" a[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -3137,7 +3128,7 @@ class TestBufferOverrun : public TestFixture {
" a[i] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_9() {
@@ -3151,7 +3142,7 @@ class TestBufferOverrun : public TestFixture {
" i += 100;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_10() {
@@ -3164,7 +3155,7 @@ class TestBufferOverrun : public TestFixture {
" char b = a[i];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_11() {
@@ -3175,7 +3166,7 @@ class TestBufferOverrun : public TestFixture {
" {\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f()\n"
"{\n"
@@ -3184,7 +3175,7 @@ class TestBufferOverrun : public TestFixture {
" {\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_15() { // ticket #1787
@@ -3196,7 +3187,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" strcpy(val, \"ab\") ;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: val\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: val\n", errout_str());
}
void buffer_overrun_16() {
@@ -3205,20 +3196,20 @@ class TestBufferOverrun : public TestFixture {
" struct Foo foo[5];\n"
" memset(foo, 0, sizeof(foo));\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n" // ticket #2093
" gchar x[3];\n"
" strcpy(x, \"12\");\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("extern char a[10];\n"
"void f() {\n"
" char b[25] = {0};\n"
" std::memcpy(b, a, 10);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_18() { // ticket #2576
@@ -3232,7 +3223,7 @@ class TestBufferOverrun : public TestFixture {
" b[i] = b[i+1];\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class A {\n"
" void foo();\n"
@@ -3244,7 +3235,7 @@ class TestBufferOverrun : public TestFixture {
" b[i] = b[i+1];\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Array 'b[7]' accessed at index 7, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Array 'b[7]' accessed at index 7, which is out of bounds.\n", errout_str());
}
void buffer_overrun_19() { // #2597 - class member with unknown type
@@ -3257,7 +3248,7 @@ class TestBufferOverrun : public TestFixture {
"A::A() {\n"
" memset(buf, 0, 10);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_21() {
@@ -3268,7 +3259,7 @@ class TestBufferOverrun : public TestFixture {
" for (size_t i = 0; i <= 4; i++)\n"
" dst[i] = src[i];\n"
"} } }");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds.\n", errout_str());
}
void buffer_overrun_24() { // index variable is changed in for-loop
@@ -3280,7 +3271,7 @@ class TestBufferOverrun : public TestFixture {
" x += array[i];\n"
" i++; }\n"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
// ticket #4096
check("void main() {\n"
@@ -3290,7 +3281,7 @@ class TestBufferOverrun : public TestFixture {
" x += array[i++];\n"
" }\n"
"}");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
}
void buffer_overrun_26() { // ticket #4432 (segmentation fault)
@@ -3301,7 +3292,7 @@ class TestBufferOverrun : public TestFixture {
" split(inbuf, f, 10, \"\t\t\");\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_27() { // ticket #4444 (segmentation fault)
@@ -3311,7 +3302,7 @@ class TestBufferOverrun : public TestFixture {
"abc(x);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// #7083: false positive: typedef and initialization with strings
@@ -3321,7 +3312,7 @@ class TestBufferOverrun : public TestFixture {
" testChar tc1 = \"\";\n"
" tc1[5]='a';\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -3331,14 +3322,14 @@ class TestBufferOverrun : public TestFixture {
"int f(S * s) {\n"
" return s->m[sizeof(s->m)];\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds.\n", errout_str());
}
void buffer_overrun_31() {
check("void f(WhereInfo *pWInfo, int *aiCur) {\n"
" memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_32() {
@@ -3349,7 +3340,7 @@ class TestBufferOverrun : public TestFixture {
" (void)strxfrm(dest,src,1);\n"
" (void)strxfrm(dest,src,2);\n"// <<
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: dest\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: dest\n", errout_str());
// destination size is too small
check("void f(void) {\n"
" const char src[3] = \"abc\";\n"
@@ -3358,7 +3349,7 @@ class TestBufferOverrun : public TestFixture {
" (void)strxfrm(dest,src,2);\n"
" (void)strxfrm(dest,src,3);\n" // <<
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: dest\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: dest\n", errout_str());
// source size is too small
check("void f(void) {\n"
" const char src[2] = \"ab\";\n"
@@ -3367,7 +3358,7 @@ class TestBufferOverrun : public TestFixture {
" (void)strxfrm(dest,src,2);\n"
" (void)strxfrm(dest,src,3);\n" // <<
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: src\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: src\n", errout_str());
// source size is too small
check("void f(void) {\n"
" const char src[1] = \"a\";\n"
@@ -3375,7 +3366,7 @@ class TestBufferOverrun : public TestFixture {
" (void)strxfrm(dest,src,1);\n"
" (void)strxfrm(dest,src,2);\n" // <<
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: src\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: src\n", errout_str());
}
void buffer_overrun_33() { // #2019
@@ -3386,7 +3377,7 @@ class TestBufferOverrun : public TestFixture {
" z[i] = 0;\n"
" return z[0];\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'z[16]' accessed at index 19, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'z[16]' accessed at index 19, which is out of bounds.\n", errout_str());
}
void buffer_overrun_34() { // #11035
@@ -3400,7 +3391,7 @@ class TestBufferOverrun : public TestFixture {
" return a[i];\n"
" }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_35() { // #2304
@@ -3410,7 +3401,7 @@ class TestBufferOverrun : public TestFixture {
" strcpy(p, q);\n"
" free(p);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: p\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: p\n", errout_str());
check("void f() {\n"
" char* q = \"0123456789\";\n"
@@ -3418,7 +3409,7 @@ class TestBufferOverrun : public TestFixture {
" strcpy(p, q);\n"
" free(p);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: p\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: p\n", errout_str());
check("typedef struct { char buf[1]; } S;\n"
"S* f() {\n"
@@ -3427,7 +3418,7 @@ class TestBufferOverrun : public TestFixture {
" sprintf((char*)s->buf, \"abc\");\n"
" return s;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_36() { // #11708
@@ -3435,7 +3426,7 @@ class TestBufferOverrun : public TestFixture {
" char a[80];\n"
" sprintf(a, \"%2.1f\", d);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_errorpath() {
@@ -3449,7 +3440,7 @@ class TestBufferOverrun : public TestFixture {
"}");
ASSERT_EQUALS("test.cpp:3:error:Buffer is accessed out of bounds: p\n"
"test.cpp:2:note:Assign p, buffer with size 10\n"
- "test.cpp:3:note:Buffer overrun\n", errout.str());
+ "test.cpp:3:note:Buffer overrun\n", errout_str());
settings0 = settingsOld;
}
@@ -3464,7 +3455,7 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" f1(a);"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// No false positive
check("void f1(char *s) {\n"
@@ -3476,7 +3467,7 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" f1(a);"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// No false negative
check("void f1(char *s) {\n"
@@ -3488,7 +3479,7 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" f1(a);"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\n", "", errout_str());
}
void buffer_overrun_function_array_argument() {
@@ -3503,7 +3494,7 @@ class TestBufferOverrun : public TestFixture {
"test.cpp:4:note:Function 'f' is called\n"
"test.cpp:1:note:Declaration of 1st function argument.\n"
"test.cpp:3:note:Passing buffer 'a' to function that is declared here\n"
- "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout.str());
+ "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str());
check("void f(float a[10][3]);\n"
"void g() {\n"
@@ -3514,7 +3505,7 @@ class TestBufferOverrun : public TestFixture {
"test.cpp:4:note:Function 'f' is called\n"
"test.cpp:1:note:Declaration of 1st function argument.\n"
"test.cpp:3:note:Passing buffer 'a' to function that is declared here\n"
- "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout.str());
+ "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str());
check("void f(int a[20]);\n"
"void g() {\n"
@@ -3525,7 +3516,7 @@ class TestBufferOverrun : public TestFixture {
"test.cpp:4:note:Function 'f' is called\n"
"test.cpp:1:note:Declaration of 1st function argument.\n"
"test.cpp:3:note:Passing buffer 'a' to function that is declared here\n"
- "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout.str());
+ "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str());
check("void f(int a[]) {\n"
" switch (2) {\n"
@@ -3536,14 +3527,14 @@ class TestBufferOverrun : public TestFixture {
"int a[1];\n"
"f(a);\n"
"");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void CreateLeafTex(unsigned char buf[256][2048][4]);\n"
"void foo() {\n"
" unsigned char(* tree)[2048][4] = new unsigned char[256][2048][4];\n"
" CreateLeafTex(tree);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int a[10]) {\n" // #10069
" int i = 0;\n"
@@ -3560,7 +3551,7 @@ class TestBufferOverrun : public TestFixture {
"test.cpp:1:note:Declaration of 1st function argument.\n"
"test.cpp:7:note:Passing buffer 'b' to function that is declared here\n"
"test.cpp:8:note:Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\n",
- errout.str());
+ errout_str());
}
void possible_buffer_overrun_1() { // #3035
@@ -3571,7 +3562,7 @@ class TestBufferOverrun : public TestFixture {
" src[99] = '\\0';\n"
" strcat(data, src);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout_str());
check("void foo() {\n"
" char * data = (char *)alloca(100);\n"
@@ -3580,19 +3571,19 @@ class TestBufferOverrun : public TestFixture {
" src[99] = '\\0';\n"
" strcat(data, src);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char src[100]) {\n"
" char * data = (char *)alloca(50);\n"
" strcat(data, src);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout_str());
check("void foo(char src[100]) {\n"
" char * data = (char *)alloca(100);\n"
" strcat(data, src);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo() {\n"
" char * data = (char *)alloca(50);\n"
@@ -3601,7 +3592,7 @@ class TestBufferOverrun : public TestFixture {
" src[99] = '\\0';\n"
" strcpy(data, src);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout_str());
check("void foo() {\n"
" char * data = (char *)alloca(100);\n"
@@ -3610,19 +3601,19 @@ class TestBufferOverrun : public TestFixture {
" src[99] = '\\0';\n"
" strcpy(data, src);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char src[100]) {\n"
" char * data = (char *)alloca(50);\n"
" strcpy(data, src);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout_str());
check("void foo(char src[100]) {\n"
" char * data = (char *)alloca(100);\n"
" strcpy(data, src);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void buffer_overrun_readSizeFromCfg() {
@@ -3644,26 +3635,26 @@ class TestBufferOverrun : public TestFixture {
" u8 str[256];\n"
" mystrcpy(str, \"abcd\");\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" u8 str[2];\n"
" mystrcpy(str, \"abcd\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str());
// The same for structs, where the message comes from a different check
check("void f() {\n"
" struct { u8 str[256]; } ms;\n"
" mystrcpy(ms.str, \"abcd\");\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" struct { u8 str[2]; } ms;\n"
" mystrcpy(ms.str, \"abcd\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: ms.str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: ms.str\n", errout_str());
}
void valueflow_string() { // using ValueFlow string values in checking
@@ -3672,7 +3663,7 @@ class TestBufferOverrun : public TestFixture {
" if (cond) x = \"abcde\";\n"
" return x[20];\n" // <- array index out of bounds when x is "abcde"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[6]' accessed at index 20, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[6]' accessed at index 20, which is out of bounds.\n", errout_str());
}
void pointer_out_of_bounds_1() {
@@ -3682,40 +3673,40 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" char *p = a + 100;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds.\n", errout_str());
check("char *f() {\n"
" char a[10];\n"
" return a + 100;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds.\n", errout_str());
check("void f(int i) {\n"
" char x[10];\n"
" if (i == 123) {}\n"
" dostuff(x+i);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds.\n", errout_str());
check("void f(int i) {\n"
" char x[10];\n"
" if (i == -1) {}\n"
" dostuff(x+i);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds.\n", errout_str());
check("void f() {\n" // #6350 - fp when there is cast of buffer
" wchar_t buf[64];\n"
" p = (unsigned char *) buf + sizeof (buf);\n"
"}", "6350.c");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() {\n"
" const char d[] = \"0123456789\";\n"
" char *cp = d + 3;\n"
" return cp - d;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void pointer_out_of_bounds_2() {
@@ -3724,7 +3715,7 @@ class TestBufferOverrun : public TestFixture {
" p += 100;\n"
" free(p);"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\n", "", errout_str());
check("void f() {\n"
" char *p = malloc(10);\n"
@@ -3732,7 +3723,7 @@ class TestBufferOverrun : public TestFixture {
" *p = 0;\n"
" free(p);"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) p is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) p is out of bounds.\n", "", errout_str());
check("void f() {\n"
" char *p = malloc(10);\n"
@@ -3741,7 +3732,7 @@ class TestBufferOverrun : public TestFixture {
" *p = 0;\n"
" free(p);"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" char *p = malloc(10);\n"
@@ -3750,7 +3741,7 @@ class TestBufferOverrun : public TestFixture {
" *p = 0;\n"
" free(p);"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void pointer_out_of_bounds_3() {
@@ -3758,7 +3749,7 @@ class TestBufferOverrun : public TestFixture {
"void f(struct S *s) {\n"
" int *p = s->a + 100;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds.\n", errout_str());
check("template class Vector\n"
"{\n"
@@ -3774,36 +3765,36 @@ class TestBufferOverrun : public TestFixture {
" const T* P1 = P2 - 1;\n"
"}\n"
"Vector> Foo;\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void pointer_out_of_bounds_4() {
check("const char* f() {\n"
" g(\"Hello\" + 6);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const char* f() {\n"
" g(\"Hello\" + 7);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic '\"Hello\"+7' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic '\"Hello\"+7' is out of bounds.\n", errout_str());
check("const char16_t* f() {\n"
" g(u\"Hello\" + 6);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("const char16_t* f() {\n"
" g(u\"Hello\" + 7);\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic 'u\"Hello\"+7' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic 'u\"Hello\"+7' is out of bounds.\n", errout_str());
check("void f() {\n" // #4647
" int val = 5;\n"
" std::string hi = \"hi\" + val;\n"
" std::cout << hi << std::endl;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic '\"hi\"+val' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic '\"hi\"+val' is out of bounds.\n", errout_str());
check("void f(const char* s, int len) {\n" // #11026
" const char* end = s + len;\n"
@@ -3813,7 +3804,7 @@ class TestBufferOverrun : public TestFixture {
" f(\"a\", 1);\n"
" f(\"bbb\", 3);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int i, const char* a) {\n" // #11140
" (void)a[i];\n"
@@ -3826,7 +3817,7 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; \"012\"[i]; ++i)\n"
" f(i, \"345\");\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -3837,26 +3828,26 @@ class TestBufferOverrun : public TestFixture {
" char x[10];\n"
" return x-1;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds.\n", errout_str());
check("void f(int i) {\n"
" char x[10];\n"
" if (i == 123) {}\n"
" dostuff(x-i);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds.\n", errout_str());
check("void f(int i) {\n"
" char x[10];\n"
" if (i == -20) {}\n"
" dostuff(x-i);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\n", "", errout_str());
check("void f(const char *x[10]) {\n"
" return x-4;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void strcat1() {
@@ -3866,7 +3857,7 @@ class TestBufferOverrun : public TestFixture {
" strcat(x.a, \"aa\");\n"
" strcat(x.a, \"aa\");\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
}
void varid1() {
@@ -3879,7 +3870,7 @@ class TestBufferOverrun : public TestFixture {
" str[30] = 0;\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void varid2() { // #4764
@@ -3887,7 +3878,7 @@ class TestBufferOverrun : public TestFixture {
" void bar() { return; }\n"
" type<> member[1];\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void assign1() {
@@ -3897,7 +3888,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" str[3] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[3]' accessed at index 3, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[3]' accessed at index 3, which is out of bounds.\n", errout_str());
}
void alloc_new() {
@@ -3906,7 +3897,7 @@ class TestBufferOverrun : public TestFixture {
" char *s; s = new char[10];\n"
" s[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str());
// ticket #1670 - false negative when using return
check("char f()\n"
@@ -3914,7 +3905,7 @@ class TestBufferOverrun : public TestFixture {
" int *s; s = new int[10];\n"
" return s[10];\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("struct Fred { char c[10]; };\n"
"char f()\n"
@@ -3922,12 +3913,12 @@ class TestBufferOverrun : public TestFixture {
" Fred *f; f = new Fred;\n"
" return f->c[10];\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\n"
"struct Thing { char data[MAX_SIZE]; };\n"
"char f4(const Thing& t) { return !t.data[0]; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo() {\n"
" char * buf; buf = new char[8];\n"
@@ -3937,7 +3928,7 @@ class TestBufferOverrun : public TestFixture {
" buf[8] = 0;\n"
" delete [] buf;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo() {\n"
" char * buf; buf = new char[8];\n"
@@ -3947,7 +3938,7 @@ class TestBufferOverrun : public TestFixture {
" buf[9] = 0;\n"
" delete [] buf;\n"
"}");
- ASSERT_EQUALS("[test.cpp:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds.\n", errout_str());
check("void foo()\n"
"{\n"
@@ -3955,7 +3946,7 @@ class TestBufferOverrun : public TestFixture {
" char *s; s = new char[Size];\n"
" s[Size] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void foo()\n"
"{\n"
@@ -3963,7 +3954,7 @@ class TestBufferOverrun : public TestFixture {
" E *e; e = new E[10];\n"
" e[10] = ZERO;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'e[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'e[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
// data is allocated with malloc
@@ -3973,14 +3964,14 @@ class TestBufferOverrun : public TestFixture {
" char *s; s = (char *)malloc(10);\n"
" s[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str());
// ticket #842
check("void f() {\n"
" int *tab4 = (int *)malloc(20 * sizeof(int));\n"
" tab4[20] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str());
// ticket #1478
check("void foo() {\n"
@@ -3989,7 +3980,7 @@ class TestBufferOverrun : public TestFixture {
" p = (char *)malloc(10);\n"
" p[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout_str());
// ticket #1134
check("void f() {\n"
@@ -3997,7 +3988,7 @@ class TestBufferOverrun : public TestFixture {
" x = (int *)malloc(10 * sizeof(int));\n"
" x[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void f() {\n"
" int *tab4; tab4 = malloc(20 * sizeof(int));\n"
@@ -4007,7 +3998,7 @@ class TestBufferOverrun : public TestFixture {
" tab4[20] = 0;\n"
" free(tab4);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" int *tab4 = malloc(20 * sizeof(int));\n"
@@ -4016,49 +4007,49 @@ class TestBufferOverrun : public TestFixture {
" tab4[20] = 0;\n"
" free(tab4);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" enum E { Size = 20 };\n"
" E *tab4 = (E *)malloc(Size * 4);\n"
" tab4[Size] = Size;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str());
check("void f() {\n"
" enum E { Size = 20 };\n"
" E *tab4 = (E *)malloc(4 * Size);\n"
" tab4[Size] = Size;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str());
check("void f() {\n"
" enum E { ZERO };\n"
" E *tab4 = (E *)malloc(20 * sizeof(E));\n"
" tab4[20] = ZERO;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str());
check("void f() {\n" // #8721
" unsigned char **cache = malloc(32);\n"
" cache[i] = malloc(65536);\n"
" cache[i][0xFFFF] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" int **a = malloc(2 * sizeof(int*));\n"
" for (int i = 0; i < 3; i++)\n"
" a[i] = NULL;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout_str());
check("void f() {\n"
" int **a = new int*[2];\n"
" for (int i = 0; i < 3; i++)\n"
" a[i] = NULL;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout_str());
}
// statically allocated buffer
@@ -4068,21 +4059,21 @@ class TestBufferOverrun : public TestFixture {
" const char *s = \"123\";\n"
" s[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[4]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[4]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void foo()\n"
"{\n"
" char *s; s = \"\";\n"
" s[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[1]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[1]' accessed at index 10, which is out of bounds.\n", errout_str());
check("void foo() {\n"
" const char *s = \"\";\n"
" s = y();\n"
" s[10] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo()\n" // #7718
"{\n"
@@ -4090,7 +4081,7 @@ class TestBufferOverrun : public TestFixture {
" s.resize(100);\n"
" s[10] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// data is allocated with alloca
@@ -4100,7 +4091,7 @@ class TestBufferOverrun : public TestFixture {
" char *s = (char *)alloca(10);\n"
" s[10] = 0;\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout_str());
}
/*
void countSprintfLength() const {
@@ -4196,13 +4187,13 @@ class TestBufferOverrun : public TestFixture {
" char c[10];\n"
" mymemset(c, 0, 10);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" char c[10];\n"
" mymemset(c, 0, 11);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str());
check("struct S {\n"
" char a[5];\n"
@@ -4211,79 +4202,79 @@ class TestBufferOverrun : public TestFixture {
" S s;\n"
" mymemset(s.a, 0, 10);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: s.a\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: s.a\n", errout_str());
check("void foo() {\n"
" char s[10];\n"
" mymemset(s, 0, '*');\n"
"}", settings);
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) The size argument is given as a char constant.\n"
- "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", errout.str());
+ "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", errout_str());
// ticket #836
check("void f(void) {\n"
" char a[10];\n"
" mymemset(a+5, 0, 10);\n"
"}", settings);
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", "", errout_str());
// Ticket #909
check("void f(void) {\n"
" char str[] = \"abcd\";\n"
" mymemset(str, 0, 6);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str());
check("void f(void) {\n"
" char str[] = \"abcd\";\n"
" mymemset(str, 0, 5);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(void) {\n"
" wchar_t str[] = L\"abcd\";\n"
" mymemset(str, 0, 21);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str());
check("void f(void) {\n"
" wchar_t str[] = L\"abcd\";\n"
" mymemset(str, 0, 20);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// ticket #1659 - overflowing variable when using memcpy
check("void f(void) {\n"
" char c;\n"
" mymemset(&c, 0, 4);\n"
"}", settings);
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", "", errout_str());
// ticket #2121 - buffer access out of bounds when using uint32_t
check("void f(void) {\n"
" unknown_type_t buf[4];\n"
" mymemset(buf, 0, 100);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #3124 - multidimensional array
check("int main() {\n"
" char b[5][6];\n"
" mymemset(b, 0, 5 * 6);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int main() {\n"
" char b[5][6];\n"
" mymemset(b, 0, 6 * 6);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: b\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: b\n", errout_str());
check("int main() {\n"
" char b[5][6];\n"
" mymemset(b, 0, 31);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: b\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: b\n", errout_str());
// #4968 - not standard function
check("void f() {\n"
@@ -4292,7 +4283,7 @@ class TestBufferOverrun : public TestFixture {
" foo::mymemset(str, 0, 100);\n"
" std::mymemset(str, 0, 100);\n"
"}", settings);
- TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", "", errout_str());
// #5257 - check strings
check("void f() {\n"
@@ -4300,18 +4291,18 @@ class TestBufferOverrun : public TestFixture {
"}", settings);
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Buffer is accessed out of bounds.\n",
"",
- errout.str());
+ errout_str());
check("void f() {\n"
" mymemset(temp, \"abc\", 4);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n" // #6816 - fp when array has known string value
" char c[10] = \"c\";\n"
" mymemset(c, 0, 10);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void minsize_sizeof() {
@@ -4333,36 +4324,36 @@ class TestBufferOverrun : public TestFixture {
" char c[7];\n"
" mystrncpy(c, \"hello\", 7);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" char c[6];\n"
" mystrncpy(c,\"hello\",6);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" char c[5];\n"
" mystrncpy(c,\"hello\",6);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str());
check("void f() {\n"
" char c[6];\n"
" mystrncpy(c,\"hello!\",7);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str());
check("void f(unsigned int addr) {\n"
" memset((void *)addr, 0, 1000);\n"
"}", settings0);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct AB { char a[10]; };\n"
"void foo(AB *ab) {\n"
" mystrncpy(x, ab->a, 100);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void a(char *p) { mystrncpy(p,\"hello world!\",10); }\n" // #3168
"void b() {\n"
@@ -4371,7 +4362,7 @@ class TestBufferOverrun : public TestFixture {
"}", settings);
TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\n",
"",
- errout.str());
+ errout_str());
}
void minsize_strlen() {
@@ -4395,13 +4386,13 @@ class TestBufferOverrun : public TestFixture {
" char str[3];\n"
" mysprintf(str, \"test\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str());
check("void f() {\n"
" char str[5];\n"
" mysprintf(str, \"%s\", \"abcde\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str());
check("int getnumber();\n"
"void f()\n"
@@ -4409,51 +4400,51 @@ class TestBufferOverrun : public TestFixture {
" char str[5];\n"
" mysprintf(str, \"%d: %s\", getnumber(), \"abcde\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", errout_str());
check("void f() {\n"
" char str[5];\n"
" mysprintf(str, \"test%s\", \"\");\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" char *str = new char[5];\n"
" mysprintf(str, \"abcde\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str());
check("void f(int condition) {\n"
" char str[5];\n"
" mysprintf(str, \"test%s\", condition ? \"12\" : \"34\");\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(int condition) {\n"
" char str[5];\n"
" mysprintf(str, \"test%s\", condition ? \"12\" : \"345\");\n"
"}", settings);
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
check("struct Foo { char a[1]; };\n"
"void f() {\n"
" struct Foo x;\n"
" mysprintf(x.a, \"aa\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout_str());
// ticket #900
check("void f() {\n"
" char *a = new char(30);\n"
" mysprintf(a, \"a\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout_str());
check("void f(char value) {\n"
" char *a = new char(value);\n"
" mysprintf(a, \"a\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout_str());
// This is out of bounds if 'sizeof(ABC)' is 1 (No padding)
check("struct Foo { char a[1]; };\n"
@@ -4461,21 +4452,21 @@ class TestBufferOverrun : public TestFixture {
" struct Foo *x = malloc(sizeof(Foo));\n"
" mysprintf(x->a, \"aa\");\n"
"}", settings);
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Buffer is accessed out of bounds: x.a\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Buffer is accessed out of bounds: x.a\n", "", errout_str());
check("struct Foo { char a[1]; };\n"
"void f() {\n"
" struct Foo *x = malloc(sizeof(Foo) + 10);\n"
" mysprintf(x->a, \"aa\");\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct Foo { char a[1]; };\n"
"void f() {\n"
" struct Foo x;\n"
" mysprintf(x.a, \"aa\");\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout_str());
check("struct Foo {\n" // #6668 - unknown size
" char a[LEN];\n"
@@ -4484,7 +4475,7 @@ class TestBufferOverrun : public TestFixture {
"void Foo::f() {\n"
" mysprintf(a, \"abcd\");\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void minsize_mul() {
@@ -4505,13 +4496,13 @@ class TestBufferOverrun : public TestFixture {
" char c[5];\n"
" myfread(c, 1, 5, stdin);\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" char c[5];\n"
" myfread(c, 1, 6, stdin);\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str());
}
// extracttests.enable
@@ -4521,7 +4512,7 @@ class TestBufferOverrun : public TestFixture {
"{\n"
" UnknownType *a = malloc(4);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// extracttests.disable
void terminateStrncpy1() {
@@ -4533,26 +4524,26 @@ class TestBufferOverrun : public TestFixture {
" strncpy(baz, bar, 100);\n"
" baz[99] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo ( char *bar ) {\n"
" char baz[100];\n"
" strncpy(baz, bar, 100);\n"
" baz[99] = '\\0';\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo ( char *bar ) {\n"
" char baz[100];\n"
" strncpy(baz, bar, 100);\n"
" baz[x+1] = '\\0';\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Test with invalid code that there is no segfault
check("char baz[100];\n"
"strncpy(baz, \"var\", 100)");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Test that there are no duplicate error messages
check("void foo ( char *bar ) {\n"
@@ -4561,7 +4552,7 @@ class TestBufferOverrun : public TestFixture {
" foo(baz);\n"
" foo(baz);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout_str());
}
void terminateStrncpy2() {
@@ -4571,7 +4562,7 @@ class TestBufferOverrun : public TestFixture {
" bar[99] = 0;\n"
" return strdup(baz);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout_str());
}
void terminateStrncpy3() {
@@ -4586,7 +4577,7 @@ class TestBufferOverrun : public TestFixture {
"void bar(char *p) {\n"
" strncpy(p, str, 100);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy().\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy().\n", errout_str());
}
void terminateStrncpy4() {
@@ -4594,13 +4585,13 @@ class TestBufferOverrun : public TestFixture {
" char buf[4];\n"
" strncpy(buf, \"ab\", 4);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void bar() {\n"
" char buf[4];\n"
" strncpy(buf, \"abcde\", 4);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy().\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy().\n", errout_str());
}
void terminateStrncpy5() { // #9944
@@ -4610,14 +4601,14 @@ class TestBufferOverrun : public TestFixture {
" return;\n"
" strncpy(v, buf.c_str(), sizeof(v));\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(const std::string& buf) {\n"
" char v[255];\n"
" if (buf.size() >= sizeof(v))\n"
" strncpy(v, buf.c_str(), sizeof(v));\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy().\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy().\n", errout_str());
}
// extracttests.enable
@@ -4646,7 +4637,7 @@ class TestBufferOverrun : public TestFixture {
" char a[10];\n"
" f2(a);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -4662,7 +4653,7 @@ class TestBufferOverrun : public TestFixture {
" struct A *str;\n"
" str = malloc(4);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void crash2() {
@@ -4727,7 +4718,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" return 0;\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char *argv[])\n"
"{\n"
@@ -4740,112 +4731,112 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" return 0;\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(const int argc, char* argv[])\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, const char* argv[])\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(const int argc, const char* argv[])\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char* argv[])\n"
"{\n"
" char prog[10] = {'\\0'};\n"
" strcat(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **argv, char **envp)\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, const char *const *const argv, char **envp)\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(const int argc, const char *const *const argv, const char *const *const envp)\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **argv, char **envp)\n"
"{\n"
" char prog[10] = {'\\0'};\n"
" strcat(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(const int argc, const char **argv, char **envp)\n"
"{\n"
" char prog[10] = {'\\0'};\n"
" strcat(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, const char **argv, char **envp)\n"
"{\n"
" char prog[10] = {'\\0'};\n"
" strcat(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(const int argc, char **argv, char **envp)\n"
"{\n"
" char prog[10] = {'\\0'};\n"
" strcat(prog, argv[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **options)\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, options[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **options)\n"
"{\n"
" char prog[10] = {'\\0'};\n"
" strcat(prog, options[0]);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **options)\n"
"{\n"
" char prog[10];\n"
" strcpy(prog, *options);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **options)\n"
"{\n"
" char prog[10];\n"
" strcpy(prog+3, *options);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
check("int main(int argc, char **argv, char **envp)\n"
"{\n"
@@ -4853,7 +4844,7 @@ class TestBufferOverrun : public TestFixture {
" if (strlen(argv[0]) < 10)\n"
" strcpy(prog, argv[0]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int main(int argc, char **argv, char **envp)\n"
"{\n"
@@ -4861,7 +4852,7 @@ class TestBufferOverrun : public TestFixture {
" if (10 > strlen(argv[0]))\n"
" strcat(prog, argv[0]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int main(int argc, char **argv, char **envp)\n"
"{\n"
@@ -4869,7 +4860,7 @@ class TestBufferOverrun : public TestFixture {
" argv[0][0] = '\\0';\n"
" strcpy(prog, argv[0]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #5835
check("int main(int argc, char* argv[]) {\n"
@@ -4878,17 +4869,17 @@ class TestBufferOverrun : public TestFixture {
" strcpy(prog, argv[0]);\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\n"
- "[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
+ "[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str());
// #7964
check("int main(int argc, char *argv[]) {\n"
" char *strcpy();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int main(int argc, char *argv[]) {\n"
" char *strcat();\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void checkBufferAllocatedWithStrlen() {
@@ -4896,33 +4887,33 @@ class TestBufferOverrun : public TestFixture {
" char *b = new char[strlen(a)];\n"
" strcpy(b, a);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
check("void f(char *a) {\n"
" char *b = new char[strlen(a) + 1];\n"
" strcpy(b, a);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char *a) {\n"
" char *b = new char[strlen(a)];\n"
" a[0] = '\\0';\n"
" strcpy(b, a);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char *a) {\n"
" char *b = (char *)malloc(strlen(a));\n"
" b = realloc(b, 10000);\n"
" strcpy(b, a);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char *a) {\n"
" char *b = (char *)malloc(strlen(a));\n"
" strcpy(b, a);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
check("void f(char *a) {\n"
" char *b = (char *)malloc(strlen(a));\n"
@@ -4930,31 +4921,31 @@ class TestBufferOverrun : public TestFixture {
" strcpy(b, a);\n"
" }\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
check("void f(char *a) {\n"
" char *b = (char *)malloc(strlen(a) + 1);\n"
" strcpy(b, a);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char *a, char *c) {\n"
" char *b = (char *)realloc(c, strlen(a));\n"
" strcpy(b, a);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
check("void f(char *a, char *c) {\n"
" char *b = (char *)realloc(c, strlen(a) + 1);\n"
" strcpy(b, a);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(char *a) {\n"
" char *b = (char *)malloc(strlen(a));\n"
" strcpy(b, a);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str());
}
void scope() {
@@ -4968,7 +4959,7 @@ class TestBufferOverrun : public TestFixture {
" X x;\n"
" x.buf[10] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("class A {\n"
"public:\n"
@@ -4980,13 +4971,15 @@ class TestBufferOverrun : public TestFixture {
" A::X x;\n"
" x.buf[10] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}
void getErrorMessages() {
// Ticket #2292: segmentation fault when using --errorlist
const Check& c = getCheck();
c.getErrorMessages(this, nullptr);
+ // we are not interested in the output - just consume it
+ (void)errout_str();
}
void arrayIndexThenCheck() {
@@ -4996,68 +4989,68 @@ class TestBufferOverrun : public TestFixture {
" if (s[i] == 'x' && i < y) {\n"
" }"
"}");
- ASSERT_EQUALS("", errout.str()); // No message because i is unknown and thus gets no varid. Avoid an internalError here.
+ ASSERT_EQUALS("", errout_str()); // No message because i is unknown and thus gets no varid. Avoid an internalError here.
check("void f(const char s[], int i) {\n"
" if (s[i] == 'x' && i < y) {\n"
" }"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str());
check("void f(const char s[]) {\n"
" for (int i = 0; s[i] == 'x' && i < y; ++i) {\n"
" }"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str());
check("void f(const int a[], unsigned i) {\n"
" if((a[i] < 2) && (i <= 42)) {\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str());
check("void f(const int a[], unsigned i) {\n"
" if((a[i] < 2) && (42 >= i)) {\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str());
// extracttests.start: int elen;
check("void f(char* e, int y) {\n"
" if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// extracttests.start: int foo(int); int func(int);
check("void f(const int a[], unsigned i) {\n"
" if(a[i] < func(i) && i <= 42) {\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str());
check("void f(const int a[], unsigned i) {\n"
" if (i <= 42 && a[i] < func(i)) {\n"
" }\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(const int a[], unsigned i) {\n"
" if (foo(a[i] + 3) < func(i) && i <= 42) {\n"
" }\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str());
check("void f(int i) {\n" // sizeof
" sizeof(a)/sizeof(a[i]) && i < 10;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// extracttests.start: extern int buf[];
check("void f(int i) {\n" // ?:
" if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void arrayIndexEarlyReturn() { // #6884
@@ -5072,7 +5065,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" return name;\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void bufferNotZeroTerminated() {
@@ -5080,19 +5073,19 @@ class TestBufferOverrun : public TestFixture {
" char c[6];\n"
" strncpy(c,\"hello!\",6);\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy().\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy().\n", errout_str());
check("void f() {\n"
" char c[6];\n"
" memcpy(c,\"hello!\",6);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\n", "", errout_str());
check("void f() {\n"
" char c[6];\n"
" memmove(c,\"hello!\",6);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\n", "", errout_str());
}
void negativeMemoryAllocationSizeError() { // #389
@@ -5102,7 +5095,7 @@ class TestBufferOverrun : public TestFixture {
" a = new int[-1];\n"
" delete [] a;\n"
"}");
- ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout_str());
check("void f()\n"
"{\n"
@@ -5110,7 +5103,7 @@ class TestBufferOverrun : public TestFixture {
" a = (int *)malloc( -10 );\n"
" free(a);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout_str());
check("void f()\n"
"{\n"
@@ -5118,14 +5111,14 @@ class TestBufferOverrun : public TestFixture {
" a = (int *)malloc( -10);\n"
" free(a);\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout_str());
check("void f()\n"
"{\n"
" int *a;\n"
" a = (int *)alloca( -10 );\n"
"}");
- TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout_str());
check("int* f(int n) {\n" // #11145
" int d = -1;\n"
@@ -5134,7 +5127,7 @@ class TestBufferOverrun : public TestFixture {
" int* p = new int[d];\n"
" return p;\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Memory allocation size is negative.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Memory allocation size is negative.\n", errout_str());
}
void negativeArraySize() {
@@ -5142,14 +5135,14 @@ class TestBufferOverrun : public TestFixture {
" int a[sz];\n"
"}\n"
"void x() { f(-100); }");
- ASSERT_EQUALS("[test.cpp:2]: (error) Declaration of array 'a' with negative size is undefined behaviour\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (error) Declaration of array 'a' with negative size is undefined behaviour\n", errout_str());
// don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance
check("int x, y;\n"
"int a[-1];\n"
"int b[x?1:-1];\n"
"int c[x?y:-1];");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void pointerAddition1() {
@@ -5157,21 +5150,18 @@ class TestBufferOverrun : public TestFixture {
" char arr[10];\n"
" char *p = arr + 20;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout_str());
check("char(*g())[1];\n" // #7950
"void f() {\n"
" int a[2];\n"
" int* b = a + sizeof(*g());\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
#define ctu(code) ctu_(code, __FILE__, __LINE__)
void ctu_(const char code[], const char* file, int line) {
- // Clear the error buffer..
- errout.str("");
-
// Tokenize..
Tokenizer tokenizer(settings0, this);
std::istringstream istr(code);
@@ -5200,7 +5190,7 @@ class TestBufferOverrun : public TestFixture {
" char *s = malloc(4);\n"
" dostuff(s);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7] -> [test.cpp:2]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7] -> [test.cpp:2]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3.\n", errout_str());
ctu("void dostuff(char *p) {\n"
" p[4] = 0;\n"
@@ -5210,7 +5200,7 @@ class TestBufferOverrun : public TestFixture {
" char *s = malloc(4);\n"
" dostuff(s);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4.\n", errout_str());
ctu("void f(int* p) {\n" // #10415
" int b[1];\n"
@@ -5222,7 +5212,7 @@ class TestBufferOverrun : public TestFixture {
" a[0] = 5;\n"
" f(a);\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20.\n", errout_str());
}
void ctu_array() {
@@ -5233,7 +5223,7 @@ class TestBufferOverrun : public TestFixture {
" char str[4];\n"
" dostuff(str);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10.\n", errout_str());
ctu("static void memclr( char *data )\n"
"{\n"
@@ -5245,7 +5235,7 @@ class TestBufferOverrun : public TestFixture {
" char str[5];\n"
" memclr( str );\n"
"}");
- ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10.\n", errout_str());
ctu("static void memclr( int i, char *data )\n"
"{\n"
@@ -5257,7 +5247,7 @@ class TestBufferOverrun : public TestFixture {
" char str[5];\n"
" memclr( 0, str );\n"
"}");
- ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10.\n", errout_str());
ctu("static void memclr( int i, char *data )\n"
"{\n"
@@ -5270,7 +5260,7 @@ class TestBufferOverrun : public TestFixture {
" memclr( 10, str );\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds.\n",
- "", errout.str());
+ "", errout_str());
// This is not an error
ctu("static void memclr( char *data, int size )\n"
@@ -5284,7 +5274,7 @@ class TestBufferOverrun : public TestFixture {
" char str[5];\n"
" memclr( str, 5 );\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #2097
ctu("void foo(int *p)\n"
@@ -5298,7 +5288,7 @@ class TestBufferOverrun : public TestFixture {
" int p[3];\n"
" foo(p+1);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9112
ctu("static void get_mac_address(const u8 *strbuf)\n"
@@ -5311,7 +5301,7 @@ class TestBufferOverrun : public TestFixture {
" u8 macstrbuf[17] = { 0 };\n"
" get_mac_address(macstrbuf);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9788
ctu("void f1(char *s) { s[2] = 'B'; }\n"
@@ -5323,7 +5313,7 @@ class TestBufferOverrun : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2.\n"
"[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2.\n",
- errout.str());
+ errout_str());
// #5140
ctu("void g(const char* argv[]) { std::cout << \"argv: \" << argv[4] << std::endl; }\n"
@@ -5332,7 +5322,7 @@ class TestBufferOverrun : public TestFixture {
" g(argv);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 4.\n",
- errout.str());
+ errout_str());
ctu("void g(const char* argv[]) { std::cout << \"argv: \" << argv[5] << std::endl; }\n"
"void f() {\n"
@@ -5340,14 +5330,14 @@ class TestBufferOverrun : public TestFixture {
" g(argv);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5.\n",
- errout.str());
+ errout_str());
ctu("void g(int *b) { b[0] = 0; }\n"
"void f() {\n"
" GLint a[1];\n"
" g(a);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
ctu("const int a[1] = { 1 };\n" // #11042
"void g(const int* d) {\n"
@@ -5357,7 +5347,7 @@ class TestBufferOverrun : public TestFixture {
" g(a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8.\n",
- errout.str());
+ errout_str());
}
void ctu_variable() {
@@ -5368,7 +5358,7 @@ class TestBufferOverrun : public TestFixture {
" int x = 4;\n"
" dostuff(&x);\n"
"}");
- ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40.\n", errout_str());
}
void ctu_arithmetic() {
@@ -5377,7 +5367,7 @@ class TestBufferOverrun : public TestFixture {
" int x[3];\n"
" dostuff(x);\n"
"}");
- ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Pointer arithmetic overflow; 'p' buffer size is 12\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Pointer arithmetic overflow; 'p' buffer size is 12\n", errout_str());
ctu("void f(const char *p) {\n" // #11361
" const char* c = p + 1;\n"
@@ -5386,7 +5376,7 @@ class TestBufferOverrun : public TestFixture {
" const char s[N] = \"ab\";\n"
" f(s);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void objectIndex() {
@@ -5396,7 +5386,7 @@ class TestBufferOverrun : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3]: (error) The address of variable 'i' is accessed at non-zero index.\n",
- errout.str());
+ errout_str());
check("int f(int j) {\n"
" int i;\n"
@@ -5404,40 +5394,40 @@ class TestBufferOverrun : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3]: (warning) The address of variable 'i' might be accessed at non-zero index.\n",
- errout.str());
+ errout_str());
check("int f() {\n"
" int i;\n"
" return (&i)[0];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(int * i) {\n"
" return i[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(std::vector i) {\n"
" return i[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f(std::vector i) {\n"
" return i.data()[1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int* f(std::vector& i) {\n"
" return &(i[1]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { int i; int j; };\n"
"int f() {\n"
" A x;\n"
" return (&x.i)[0];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct A { int i; int j; };\n"
"int f() {\n"
@@ -5445,7 +5435,7 @@ class TestBufferOverrun : public TestFixture {
" int * i = &x.i;\n"
" return i[0];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f() {\n"
" int x = 0;\n"
@@ -5453,7 +5443,7 @@ class TestBufferOverrun : public TestFixture {
" m[0] = &x;\n"
" m[1] = &x;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int f() {\n"
" int x = 0;\n"
@@ -5463,7 +5453,7 @@ class TestBufferOverrun : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:5]: (error) The address of variable 'x' is accessed at non-zero index.\n",
- errout.str());
+ errout_str());
check("int x = 0;\n"
"int f() {\n"
@@ -5473,7 +5463,7 @@ class TestBufferOverrun : public TestFixture {
"}");
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:5]: (error) The address of variable 'x' is accessed at non-zero index.\n",
- errout.str());
+ errout_str());
check("int f(int * y) {\n"
" int x = 0;\n"
@@ -5482,7 +5472,7 @@ class TestBufferOverrun : public TestFixture {
" m[1] = y;\n"
" return m[1][1];\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void print(char** test);\n"
"int main(){\n"
@@ -5497,7 +5487,7 @@ class TestBufferOverrun : public TestFixture {
TODO_ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:9]: (warning) The address of local variable 'test' might be accessed at non-zero index.\n",
"",
- errout.str());
+ errout_str());
check("void Bar(uint8_t data);\n"
"void Foo(const uint8_t * const data, const uint8_t length) {\n"
@@ -5508,7 +5498,7 @@ class TestBufferOverrun : public TestFixture {
" const uint8_t data = 0U;\n"
" Foo(&data,1U);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int foo(int n, int* p) {\n"
" int res = 0;\n"
@@ -5520,7 +5510,7 @@ class TestBufferOverrun : public TestFixture {
" int single_value = 0;\n"
" return foo(1, &single_value);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(const char* app, size_t applen) {\n" // #10137
" char* tmp_de = NULL;\n"
@@ -5533,7 +5523,7 @@ class TestBufferOverrun : public TestFixture {
" }\n"
" free(*str);\n"
"}\n", "test.c");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("template \n"
"using vector = Eigen::Matrix;\n"
@@ -5542,7 +5532,7 @@ class TestBufferOverrun : public TestFixture {
" vector* out_row = &out(r, 0);\n"
" out_row[c] = vector(1,2);\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(const uint8_t* d, const uint8_t L) {\n" // #10092
" for (uint8_t i = 0U; i < L; ++i)\n"
@@ -5552,45 +5542,45 @@ class TestBufferOverrun : public TestFixture {
" const uint8_t u = 4;\n"
" f(&u, N);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("uint32_t f(uint32_t u) {\n" // #10154
" return ((uint8_t*)&u)[3];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("uint32_t f(uint32_t u) {\n"
" return ((uint8_t*)&u)[4];\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout_str());
check("uint32_t f(uint32_t u) {\n"
" return reinterpret_cast(&u)[3];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("uint32_t f(uint32_t u) {\n"
" return reinterpret_cast(&u)[4];\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout_str());
check("uint32_t f(uint32_t u) {\n"
" uint8_t* p = (uint8_t*)&u;\n"
" return p[3];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("uint32_t f(uint32_t u) {\n"
" uint8_t* p = (uint8_t*)&u;\n"
" return p[4];\n"
"}\n");
- ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout_str());
check("uint32_t f(uint32_t* pu) {\n"
" uint8_t* p = (uint8_t*)pu;\n"
" return p[4];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct S { uint8_t padding[500]; };\n" // #10133
"S s = { 0 };\n"
@@ -5598,7 +5588,7 @@ class TestBufferOverrun : public TestFixture {
" uint8_t* p = (uint8_t*)&s;\n"
" return p[10];\n"
"}\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("struct X {\n" // #2654
" int a;\n"
@@ -5611,7 +5601,7 @@ class TestBufferOverrun : public TestFixture {
" (void)y[1];\n"
" (void)y[2];\n"
"}\n");
- TODO_ASSERT_EQUALS("error", "", errout.str());
+ TODO_ASSERT_EQUALS("error", "", errout_str());
}
void checkPipeParameterSize() { // #3521
@@ -5624,7 +5614,7 @@ class TestBufferOverrun : public TestFixture {
" return;\n"
" }\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: pipefd\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: pipefd\n", errout_str());
check("void f(){\n"
"int pipefd[2];\n"
@@ -5632,7 +5622,7 @@ class TestBufferOverrun : public TestFixture {
" return;\n"
" }\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void f(){\n"
"char pipefd[2];\n"
@@ -5640,7 +5630,7 @@ class TestBufferOverrun : public TestFixture {
" return;\n"
" }\n"
"}", settings);
- ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: (int*)pipefd\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: (int*)pipefd\n", errout_str());
check("void f(){\n"
"char pipefd[20];\n" // Strange, but large enough
@@ -5648,7 +5638,7 @@ class TestBufferOverrun : public TestFixture {
" return;\n"
" }\n"
"}", settings);
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
};
diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp
index 115ebb7baff..15198feb224 100644
--- a/test/testcharvar.cpp
+++ b/test/testcharvar.cpp
@@ -41,9 +41,6 @@ class TestCharVar : public TestFixture {
#define check(code) check_(code, __FILE__, __LINE__)
void check_(const char code[], const char* file, int line) {
- // Clear the error buffer..
- errout.str("");
-
// Tokenize..
Tokenizer tokenizer(settings, this);
std::istringstream istr(code);
@@ -61,7 +58,7 @@ class TestCharVar : public TestFixture {
" unsigned char ch = 0x80;\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int buf[256];\n"
"void foo()\n"
@@ -69,7 +66,7 @@ class TestCharVar : public TestFixture {
" char ch = 0x80;\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (portability) 'char' type used as array index.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (portability) 'char' type used as array index.\n", errout_str());
check("int buf[256];\n"
"void foo()\n"
@@ -77,7 +74,7 @@ class TestCharVar : public TestFixture {
" char ch = 0;\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int buf[256];\n"
"void foo()\n"
@@ -85,7 +82,7 @@ class TestCharVar : public TestFixture {
" signed char ch = 0;\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int buf[256];\n"
"void foo()\n"
@@ -93,67 +90,67 @@ class TestCharVar : public TestFixture {
" char ch = 0x80;\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:5]: (portability) 'char' type used as array index.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (portability) 'char' type used as array index.\n", errout_str());
check("int buf[256];\n"
"void foo(signed char ch)\n"
"{\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int buf[256];\n"
"void foo(char ch)\n"
"{\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* buf)\n"
"{\n"
" char ch = 0x80;"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (portability) 'char' type used as array index.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (portability) 'char' type used as array index.\n", errout_str());
check("void foo(char* buf)\n"
"{\n"
" char ch = 0;"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* buf)\n"
"{\n"
" buf['A'] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char* buf, char ch)\n"
"{\n"
" buf[ch] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int flags[256];\n"
"void foo(const char* str)\n"
"{\n"
" flags[*str] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("int flags[256];\n"
"void foo(const char* str)\n"
"{\n"
" flags[(unsigned char)*str] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(const char str[])\n"
"{\n"
" map[str] = 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void array_index_2() {
@@ -163,7 +160,7 @@ class TestCharVar : public TestFixture {
" const char *s = \"abcde\";\n"
" foo(s[i]);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void bitop() {
@@ -171,32 +168,32 @@ class TestCharVar : public TestFixture {
" signed char ch = -1;\n"
" *result = a | ch;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout_str());
check("void foo(int *result) {\n"
" unsigned char ch = -1;\n"
" *result = a | ch;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
check("void foo(char *result) {\n"
" signed char ch = -1;\n"
" *result = a | ch;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// 0x03 & ..
check("void foo(int *result) {\n"
" signed char ch = -1;\n"
" *result = 0x03 | ch;\n"
"}");
- ASSERT_EQUALS("[test.cpp:3]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout_str());
check("void foo(int *result) {\n"
" signed char ch = -1;\n"
" *result = 0x03 & ch;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
};
diff --git a/test/testclass.cpp b/test/testclass.cpp
index 06b44130644..c68ee5ca1ba 100644
--- a/test/testclass.cpp
+++ b/test/testclass.cpp
@@ -247,8 +247,6 @@ class TestClass : public TestFixture {
#define checkCopyCtorAndEqOperator(code) checkCopyCtorAndEqOperator_(code, __FILE__, __LINE__)
void checkCopyCtorAndEqOperator_(const char code[], const char* file, int line) {
- // Clear the error log
- errout.str("");
const Settings settings = settingsBuilder().severity(Severity::warning).build();
Preprocessor preprocessor(settings);
@@ -269,25 +267,25 @@ class TestClass : public TestFixture {
" A(const A& other) { }\n"
" A& operator=(const A& other) { return *this; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyCtorAndEqOperator("class A\n"
"{\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyCtorAndEqOperator("class A\n"
"{\n"
" A(const A& other) { }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyCtorAndEqOperator("class A\n"
"{\n"
" A& operator=(const A& other) { return *this; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyCtorAndEqOperator("class A\n"
@@ -295,7 +293,7 @@ class TestClass : public TestFixture {
" A(const A& other) { }\n"
" int x;\n"
"};");
- TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\n", "", errout_str());
// TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator'
checkCopyCtorAndEqOperator("class A\n"
@@ -303,7 +301,7 @@ class TestClass : public TestFixture {
" A& operator=(const A& other) { return *this; }\n"
" int x;\n"
"};");
- TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\n", "", errout_str());
// TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor'
checkCopyCtorAndEqOperator("class A\n"
@@ -311,7 +309,7 @@ class TestClass : public TestFixture {
" A& operator=(const int &x) { this->x = x; return *this; }\n"
" int x;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyCtorAndEqOperator("class A {\n"
"public:\n"
@@ -331,7 +329,7 @@ class TestClass : public TestFixture {
"private:\n"
" static int i;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #7987 - Don't show warning when there is a move constructor
checkCopyCtorAndEqOperator("struct S {\n"
@@ -342,21 +340,18 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #8337 - False positive in copy constructor detection
checkCopyCtorAndEqOperator("struct StaticListNode {\n"
" StaticListNode(StaticListNode*& prev) : m_next(0) {}\n"
" StaticListNode* m_next;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
#define checkExplicitConstructors(code) checkExplicitConstructors_(code, __FILE__, __LINE__)
void checkExplicitConstructors_(const char code[], const char* file, int line) {
- // Clear the error log
- errout.str("");
-
Preprocessor preprocessor(settings0);
// Tokenize..
@@ -378,7 +373,7 @@ class TestClass : public TestFixture {
" explicit Class(const std::string&) { }\n"
" Class(int a, int b) { }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Class {\n"
" Class() = delete;\n"
@@ -386,7 +381,7 @@ class TestClass : public TestFixture {
" explicit Class(Class&& other) { }\n"
" virtual int i() = 0;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Class {\n"
" Class() = delete;\n"
@@ -394,37 +389,37 @@ class TestClass : public TestFixture {
" Class(Class&& other) = delete;\n"
" virtual int i() = 0;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Class {\n"
" Class(int i) { }\n"
"};");
- ASSERT_EQUALS("[test.cpp:2]: (style) Class 'Class' has a constructor with 1 argument that is not explicit.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Class 'Class' has a constructor with 1 argument that is not explicit.\n", errout_str());
checkExplicitConstructors("class Class {\n"
" Class(const Class& other) { }\n"
" virtual int i() = 0;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Class {\n"
" Class(Class&& other) { }\n"
" virtual int i() = 0;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #6585
checkExplicitConstructors("class Class {\n"
" private: Class(const Class&);\n"
" virtual int i() = 0;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Class {\n"
" public: Class(const Class&);\n"
" virtual int i() = 0;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #7465: Error properly reported in templates
checkExplicitConstructors("template struct Test {\n"
@@ -435,7 +430,7 @@ class TestClass : public TestFixture {
" Test test;\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("[test.cpp:2]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:2]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit.\n", errout_str());
// #7465: No error for copy or move constructors
checkExplicitConstructors("template struct Test {\n"
@@ -448,7 +443,7 @@ class TestClass : public TestFixture {
" Test test;\n"
" return 0;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #8600
checkExplicitConstructors("struct A { struct B; };\n"
@@ -456,12 +451,12 @@ class TestClass : public TestFixture {
" B() = default;\n"
" B(const B&) {}\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("struct A{"
" A(int, int y=2) {}"
"};");
- ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout_str());
checkExplicitConstructors("struct Foo {\n" // #10515
" template \n"
@@ -474,27 +469,27 @@ class TestClass : public TestFixture {
"struct Baz {\n"
" explicit constexpr Baz(int) {}\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Token;\n" // #11126
"struct Branch {\n"
" Branch(Token* tok = nullptr) : endBlock(tok) {}\n"
" Token* endBlock = nullptr;\n"
"};\n");
- ASSERT_EQUALS("[test.cpp:3]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit.\n", errout_str());
checkExplicitConstructors("struct S {\n"
" S(std::initializer_list il) : v(il) {}\n"
" std::vector v;\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("template\n" // #10977
"struct A {\n"
" template\n"
" A(Ts&&... ts) {}\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkExplicitConstructors("class Color {\n" // #7176
"public:\n"
@@ -503,14 +498,11 @@ class TestClass : public TestFixture {
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Class 'Color' has a constructor with 1 argument that is not explicit.\n"
"[test.cpp:4]: (style) Class 'Color' has a constructor with 1 argument that is not explicit.\n",
- errout.str());
+ errout_str());
}
#define checkDuplInheritedMembers(code) checkDuplInheritedMembers_(code, __FILE__, __LINE__)
void checkDuplInheritedMembers_(const char code[], const char* file, int line) {
- // Clear the error log
- errout.str("");
-
Preprocessor preprocessor(settings1);
// Tokenize..
@@ -530,7 +522,7 @@ class TestClass : public TestFixture {
"struct Derived : Base {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("class Base {\n"
" protected:\n"
@@ -539,7 +531,7 @@ class TestClass : public TestFixture {
"struct Derived : Base {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout_str());
checkDuplInheritedMembers("class Base {\n"
" protected:\n"
@@ -548,7 +540,7 @@ class TestClass : public TestFixture {
"struct Derived : public Base {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout_str());
checkDuplInheritedMembers("class Base0 {\n"
" int x;\n"
@@ -559,7 +551,7 @@ class TestClass : public TestFixture {
"struct Derived : Base0, Base1 {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("class Base0 {\n"
" protected:\n"
@@ -571,7 +563,7 @@ class TestClass : public TestFixture {
"struct Derived : Base0, Base1 {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:9]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:9]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n", errout_str());
checkDuplInheritedMembers("class Base0 {\n"
" protected:\n"
@@ -585,7 +577,7 @@ class TestClass : public TestFixture {
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n"
- "[test.cpp:7] -> [test.cpp:10]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'.\n", errout.str());
+ "[test.cpp:7] -> [test.cpp:10]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'.\n", errout_str());
checkDuplInheritedMembers("class Base {\n"
" int x;\n"
@@ -593,7 +585,7 @@ class TestClass : public TestFixture {
"struct Derived : Base {\n"
" int y;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("class A {\n"
" int x;\n"
@@ -601,20 +593,20 @@ class TestClass : public TestFixture {
"struct B {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Unknown 'Base' class
checkDuplInheritedMembers("class Derived : public UnknownBase {\n"
" int x;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("class Base {\n"
" int x;\n"
"};\n"
"class Derived : public Base {\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #6692
checkDuplInheritedMembers("namespace test1 {\n"
@@ -626,7 +618,7 @@ class TestClass : public TestFixture {
" int Value;\n"
" };\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9957
checkDuplInheritedMembers("class Base {\n"
@@ -640,12 +632,12 @@ class TestClass : public TestFixture {
"class Derived2 : public Derived1 {\n"
" int i;\n"
"};");
- ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'.\n", errout_str());
// don't crash on recursive template
checkDuplInheritedMembers("template\n"
"struct BitInt : public BitInt { };");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// don't crash on recursive template
checkDuplInheritedMembers("namespace _impl {\n"
@@ -660,13 +652,13 @@ class TestClass : public TestFixture {
" struct fn_traits\n"
" : public fn_traits {};\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #10594
checkDuplInheritedMembers("template struct A { bool a = true; };\n"
"struct B { bool a; };\n"
"template<> struct A<1> : B {};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("struct B {\n"
" int g() const;\n"
@@ -677,7 +669,7 @@ class TestClass : public TestFixture {
" int f() const override { return g(); }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'.\n",
- errout.str());
+ errout_str());
checkDuplInheritedMembers("struct B {\n"
" int g() const;\n"
@@ -685,7 +677,7 @@ class TestClass : public TestFixture {
"struct D : B {\n"
" int g(int) const;\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("struct S {\n"
" struct T {\n"
@@ -695,7 +687,7 @@ class TestClass : public TestFixture {
"struct T : S::T {\n"
" T() : S::T() {}\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("struct S {};\n" // #11827
"struct SPtr {\n"
@@ -706,7 +698,7 @@ class TestClass : public TestFixture {
"struct TPtr : public SPtr {\n"
" T* operator->() const { return (T*)p; }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("struct B { virtual int& get() = 0; };\n" // #12311
"struct D : B {\n"
@@ -714,7 +706,7 @@ class TestClass : public TestFixture {
" int& get() override { return i; }\n"
" const int& get() const { return i; }\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkDuplInheritedMembers("class Base {\n" // #12353
" public:\n"
@@ -725,14 +717,11 @@ class TestClass : public TestFixture {
"public:\n"
" void Two() = delete;\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
void checkCopyConstructor_(const char code[], const char* file, int line) {
- // Clear the error log
- errout.str("");
-
Preprocessor preprocessor(settings3);
// Tokenize..
@@ -763,7 +752,7 @@ class TestClass : public TestFixture {
" F&operator=(const F&);\n"
" ~F();\n"
"};");
- TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n", "", errout_str());
checkCopyConstructor("class F {\n"
" char *p;\n"
@@ -779,7 +768,7 @@ class TestClass : public TestFixture {
TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n",
"[test.cpp:4]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
- , errout.str());
+ , errout_str());
checkCopyConstructor("class F\n"
"{\n"
@@ -799,7 +788,7 @@ class TestClass : public TestFixture {
TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n",
""
- , errout.str());
+ , errout_str());
checkCopyConstructor("class kalci\n"
"{\n"
@@ -826,7 +815,7 @@ class TestClass : public TestFixture {
" ~kalci();\n"
" kalci& operator=(const kalci&kalci);\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class F\n"
"{\n"
@@ -851,7 +840,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- TODO_ASSERT_EQUALS("[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout_str());
checkCopyConstructor("class F {\n"
" char *c;\n"
@@ -865,7 +854,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class F {\n"
" char *c;\n"
@@ -879,7 +868,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout_str());
checkCopyConstructor("class F\n"
"{\n"
@@ -894,7 +883,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- TODO_ASSERT_EQUALS("[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", "", errout.str());
+ TODO_ASSERT_EQUALS("[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", "", errout_str());
checkCopyConstructor("class F\n"
"{\n"
@@ -918,7 +907,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class F : E\n"
"{\n"
@@ -929,7 +918,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class E { E(E&); };\n" // non-copyable
"class F : E\n"
@@ -941,7 +930,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class E {};\n"
"class F : E {\n"
@@ -952,7 +941,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("[test.cpp:5]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str());
checkCopyConstructor("class F {\n"
" char *p;\n"
@@ -963,7 +952,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class F {\n"
" char *p;\n"
@@ -971,7 +960,7 @@ class TestClass : public TestFixture {
" ~F();\n"
" F& operator=(const F&f);\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str());
// #7198
checkCopyConstructor("struct F {\n"
@@ -980,7 +969,7 @@ class TestClass : public TestFixture {
" p = malloc(100);\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void copyConstructor2() { // ticket #4458
@@ -997,7 +986,7 @@ class TestClass : public TestFixture {
" Vector& operator=(const Vector&v);\n"
" _Tp* _M_finish;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void copyConstructor3() {
@@ -1008,7 +997,7 @@ class TestClass : public TestFixture {
" F&operator=(const F &f);\n"
" ~F();\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("struct F {\n"
" char* c;\n"
@@ -1017,7 +1006,7 @@ class TestClass : public TestFixture {
" F&operator=(const F &f);\n"
" ~F();\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor.\n", errout_str());
}
void copyConstructor4() {
@@ -1040,7 +1029,7 @@ class TestClass : public TestFixture {
"private:\n"
" int* m_ptr;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void copyConstructor5() {
@@ -1053,7 +1042,7 @@ class TestClass : public TestFixture {
"private:\n"
" int* m_ptr;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("class Copyable {};\n"
"\n"
@@ -1064,7 +1053,7 @@ class TestClass : public TestFixture {
"private:\n"
" int* m_ptr;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void copyConstructor6() {
@@ -1079,7 +1068,7 @@ class TestClass : public TestFixture {
"[test.cpp:4]: (warning) Struct 'S' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).\n"
"[test.cpp:4]: (warning) Struct 'S' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n",
"",
- errout.str());
+ errout_str());
}
void noOperatorEq() {
@@ -1089,7 +1078,7 @@ class TestClass : public TestFixture {
" F(const F &f);\n"
" ~F();\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str());
// defaulted operator=
checkCopyConstructor("struct F {\n"
@@ -1099,7 +1088,7 @@ class TestClass : public TestFixture {
" F &operator=(const F &f) = default;\n"
" ~F();\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=.\n", errout_str());
// deleted operator=
checkCopyConstructor("struct F {\n"
@@ -1109,7 +1098,7 @@ class TestClass : public TestFixture {
" F &operator=(const F &f) = delete;\n"
" ~F();\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// base class deletes operator=
checkCopyConstructor("struct F : NonCopyable {\n"
@@ -1118,7 +1107,7 @@ class TestClass : public TestFixture {
" F(const F &f);\n"
" ~F();\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void noDestructor() {
@@ -1128,7 +1117,7 @@ class TestClass : public TestFixture {
" F(const F &f);\n"
" F&operator=(const F&);"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str());
checkCopyConstructor("struct F {\n"
" C* c;\n"
@@ -1136,7 +1125,7 @@ class TestClass : public TestFixture {
" F(const F &f);\n"
" F&operator=(const F&);"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkCopyConstructor("struct F {\n"
" int* i;\n"
@@ -1144,7 +1133,7 @@ class TestClass : public TestFixture {
" F(const F &f);\n"
" F& operator=(const F&);"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str());
checkCopyConstructor("struct Data { int x; int y; };\n"
"struct F {\n"
@@ -1153,7 +1142,7 @@ class TestClass : public TestFixture {
" F(const F &f);\n"
" F&operator=(const F&);"
"};");
- ASSERT_EQUALS("[test.cpp:4]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str());
// defaulted destructor
checkCopyConstructor("struct F {\n"
@@ -1163,7 +1152,7 @@ class TestClass : public TestFixture {
" F &operator=(const F &f);\n"
" ~F() = default;\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor.\n", errout_str());
// deleted destructor
checkCopyConstructor("struct F {\n"
@@ -1173,15 +1162,12 @@ class TestClass : public TestFixture {
" F &operator=(const F &f);\n"
" ~F() = delete;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// Check that operator Equal returns reference to this
#define checkOpertorEqRetRefThis(code) checkOpertorEqRetRefThis_(code, __FILE__, __LINE__)
void checkOpertorEqRetRefThis_(const char code[], const char* file, int line) {
- // Clear the error log
- errout.str("");
-
Preprocessor preprocessor(settings0);
// Tokenize..
@@ -1201,7 +1187,7 @@ class TestClass : public TestFixture {
"public:\n"
" A & operator=(const A &a) { return *this; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1209,7 +1195,7 @@ class TestClass : public TestFixture {
"public:\n"
" A & operator=(const A &a) { return a; }\n"
"};");
- ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1218,7 +1204,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &);\n"
"};\n"
"A & A::operator=(const A &a) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1227,7 +1213,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &a);\n"
"};\n"
"A & A::operator=(const A &a) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1236,7 +1222,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &);\n"
"};\n"
"A & A::operator=(const A &a) { return a; }");
- ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1245,7 +1231,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &a);\n"
"};\n"
"A & A::operator=(const A &a) { return a; }");
- ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1257,7 +1243,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &b) { return *this; }\n"
" };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1269,7 +1255,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &b) { return b; }\n"
" };\n"
"};");
- ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1282,7 +1268,7 @@ class TestClass : public TestFixture {
" };\n"
"};\n"
"A::B & A::B::operator=(const A::B &b) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A\n"
@@ -1295,7 +1281,7 @@ class TestClass : public TestFixture {
" };\n"
"};\n"
"A::B & A::B::operator=(const A::B &b) { return b; }");
- ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1305,7 +1291,7 @@ class TestClass : public TestFixture {
"{\n"
" B & operator=(const B & b) { return b; }\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1316,7 +1302,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &);\n"
"};\n"
"A::B & A::B::operator=(const A::B & b) { return b; }");
- ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1326,7 +1312,7 @@ class TestClass : public TestFixture {
"{\n"
" A::B & operator=(const A::B & b) { return b; }\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1337,7 +1323,7 @@ class TestClass : public TestFixture {
" A::B & operator=(const A::B &);\n"
"};\n"
"A::B & A::B::operator=(const A::B & b) { return b; }");
- ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace A {\n"
@@ -1347,7 +1333,7 @@ class TestClass : public TestFixture {
"{\n"
" B & operator=(const B & b) { return b; }\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace A {\n"
@@ -1358,7 +1344,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &);\n"
"};\n"
"A::B & A::B::operator=(const A::B & b) { return b; }");
- ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace A {\n"
@@ -1368,7 +1354,7 @@ class TestClass : public TestFixture {
"{\n"
" A::B & operator=(const A::B & b) { return b; }\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace A {\n"
@@ -1379,7 +1365,7 @@ class TestClass : public TestFixture {
" A::B & operator=(const A::B &);\n"
"};\n"
"A::B & A::B::operator=(const A::B & b) { return b; }");
- ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis( // #11380
"struct S {\n"
@@ -1389,7 +1375,7 @@ class TestClass : public TestFixture {
" }\n"
" int i;\n"
"};\n");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqRetRefThis2() {
@@ -1399,7 +1385,7 @@ class TestClass : public TestFixture {
"{\n"
" szp &operator =(int *other) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"class szp\n"
@@ -1407,7 +1393,7 @@ class TestClass : public TestFixture {
" szp &operator =(int *other);\n"
"};\n"
"szp &szp::operator =(int *other) {}");
- ASSERT_EQUALS("[test.cpp:5]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace NS {\n"
@@ -1417,7 +1403,7 @@ class TestClass : public TestFixture {
"{\n"
" szp &operator =(int *other) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace NS {\n"
@@ -1428,7 +1414,7 @@ class TestClass : public TestFixture {
" szp &operator =(int *other);\n"
"};\n"
"NS::szp &NS::szp::operator =(int *other) {}");
- ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace NS {\n"
@@ -1438,7 +1424,7 @@ class TestClass : public TestFixture {
"{\n"
" NS::szp &operator =(int *other) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"namespace NS {\n"
@@ -1449,7 +1435,7 @@ class TestClass : public TestFixture {
" NS::szp &operator =(int *other);\n"
"};\n"
"NS::szp &NS::szp::operator =(int *other) {}");
- ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1459,7 +1445,7 @@ class TestClass : public TestFixture {
"{\n"
" szp &operator =(int *other) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1470,7 +1456,7 @@ class TestClass : public TestFixture {
" szp &operator =(int *other);\n"
"};\n"
"A::szp &A::szp::operator =(int *other) {}");
- ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1480,7 +1466,7 @@ class TestClass : public TestFixture {
"{\n"
" A::szp &operator =(int *other) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1491,7 +1477,7 @@ class TestClass : public TestFixture {
" A::szp &operator =(int *other);\n"
"};\n"
"A::szp &A::szp::operator =(int *other) {}");
- ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
}
void operatorEqRetRefThis3() {
@@ -1502,7 +1488,7 @@ class TestClass : public TestFixture {
" inline A &operator =(int *other) { return (*this); };\n"
" inline A &operator =(long *other) { return (*this = 0); };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1512,7 +1498,7 @@ class TestClass : public TestFixture {
"};\n"
"A &A::operator =(int *other) { return (*this); };\n"
"A &A::operator =(long *other) { return (*this = 0); };");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1520,7 +1506,7 @@ class TestClass : public TestFixture {
" inline A &operator =(int *other) { return (*this); };\n"
" inline A &operator =(long *other) { return operator = (*(int *)other); };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1530,7 +1516,7 @@ class TestClass : public TestFixture {
"};\n"
"A &A::operator =(int *other) { return (*this); };\n"
"A &A::operator =(long *other) { return operator = (*(int *)other); };");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1540,7 +1526,7 @@ class TestClass : public TestFixture {
"};\n"
"A &A::operator =(int *other) { return (*this); };\n"
"A &A::operator =(long *other) { return this->operator = (*(int *)other); };");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqRetRefThis( // #9045
"class V {\n"
@@ -1552,7 +1538,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqRetRefThis4() {
@@ -1562,7 +1548,7 @@ class TestClass : public TestFixture {
"{\n"
" return (P&)(*this += pc);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqRetRefThis5() {
@@ -1572,21 +1558,21 @@ class TestClass : public TestFixture {
"public:\n"
" A & operator=(const A &a) { }\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
"protected:\n"
" A & operator=(const A &a) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
"private:\n"
" A & operator=(const A &a) {}\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1596,7 +1582,7 @@ class TestClass : public TestFixture {
" throw std::exception();\n"
" }\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1606,7 +1592,7 @@ class TestClass : public TestFixture {
" abort();\n"
" }\n"
"};");
- ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented.\n", errout_str());
checkOpertorEqRetRefThis(
"class A {\n"
@@ -1614,7 +1600,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &a);\n"
"};\n"
"A & A :: operator=(const A &a) { }");
- ASSERT_EQUALS("[test.cpp:5]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str());
}
void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)
@@ -1649,15 +1635,12 @@ class TestClass : public TestFixture {
" return replaceImplDiscr();\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// Check that operator Equal checks for assignment to self
#define checkOpertorEqToSelf(code) checkOpertorEqToSelf_(code, __FILE__, __LINE__)
void checkOpertorEqToSelf_(const char code[], const char* file, int line) {
- // Clear the error log
- errout.str("");
-
Preprocessor preprocessor(settings1);
// Tokenize..
@@ -1678,7 +1661,7 @@ class TestClass : public TestFixture {
"public:\n"
" A & operator=(const A &a) { if (&a != this) { } return *this; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test doesn't have an assignment test but it is not needed
checkOpertorEqToSelf(
@@ -1687,7 +1670,7 @@ class TestClass : public TestFixture {
"public:\n"
" A & operator=(const A &a) { return *this; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test and has it
checkOpertorEqToSelf(
@@ -1705,7 +1688,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this class needs an assignment test but doesn't have it
checkOpertorEqToSelf(
@@ -1720,7 +1703,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test has an assignment test but doesn't need it
checkOpertorEqToSelf(
@@ -1730,7 +1713,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &);\n"
"};\n"
"A & A::operator=(const A &a) { if (&a != this) { } return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test doesn't have an assignment test but doesn't need it
checkOpertorEqToSelf(
@@ -1740,7 +1723,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &);\n"
"};\n"
"A & A::operator=(const A &a) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test and has it
checkOpertorEqToSelf(
@@ -1759,7 +1742,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1778,7 +1761,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1797,7 +1780,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1816,7 +1799,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1835,7 +1818,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1854,7 +1837,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1876,7 +1859,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test and has the inverse test
checkOpertorEqToSelf(
@@ -1897,7 +1880,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test needs an assignment test but doesn’t have it
@@ -1914,7 +1897,7 @@ class TestClass : public TestFixture {
" s = strdup(a.s);\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// ticket #1224
checkOpertorEqToSelf(
@@ -1932,7 +1915,7 @@ class TestClass : public TestFixture {
" delete oldtree;\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
@@ -1948,7 +1931,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &b) { if (&b != this) { } return *this; }\n"
" };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test doesn't have an assignment test but doesn't need it
checkOpertorEqToSelf(
@@ -1961,7 +1944,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &b) { return *this; }\n"
" };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test but has it
checkOpertorEqToSelf(
@@ -1981,7 +1964,7 @@ class TestClass : public TestFixture {
" }\n"
" };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test but doesn't have it
checkOpertorEqToSelf(
@@ -2000,7 +1983,7 @@ class TestClass : public TestFixture {
" }\n"
" };\n"
"};");
- ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
// this test has an assignment test but doesn't need it
checkOpertorEqToSelf(
@@ -2014,7 +1997,7 @@ class TestClass : public TestFixture {
" };\n"
"};\n"
"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test doesn't have an assignment test but doesn't need it
checkOpertorEqToSelf(
@@ -2028,7 +2011,7 @@ class TestClass : public TestFixture {
" };\n"
"};\n"
"A::B & A::B::operator=(const A::B &b) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test and has it
checkOpertorEqToSelf(
@@ -2051,7 +2034,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
" }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test needs an assignment test but doesn't have it
checkOpertorEqToSelf(
@@ -2071,7 +2054,7 @@ class TestClass : public TestFixture {
" s = strdup(b.s);\n"
" return *this;\n"
" }");
- ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
}
void operatorEqToSelf3() {
@@ -2082,7 +2065,7 @@ class TestClass : public TestFixture {
"public:\n"
" A & operator=(const A &a) { return *this; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
checkOpertorEqToSelf(
@@ -2097,7 +2080,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it
checkOpertorEqToSelf(
@@ -2107,7 +2090,7 @@ class TestClass : public TestFixture {
" A & operator=(const A &);\n"
"};\n"
"A & A::operator=(const A &a) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
checkOpertorEqToSelf(
@@ -2123,7 +2106,7 @@ class TestClass : public TestFixture {
" s = strdup(a.s);\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqToSelf4() {
@@ -2138,7 +2121,7 @@ class TestClass : public TestFixture {
" B & operator=(const B &b) { return *this; }\n"
" };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
checkOpertorEqToSelf(
@@ -2157,7 +2140,7 @@ class TestClass : public TestFixture {
" }\n"
" };\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it
checkOpertorEqToSelf(
@@ -2171,7 +2154,7 @@ class TestClass : public TestFixture {
" };\n"
"};\n"
"A::B & A::B::operator=(const A::B &b) { return *this; }");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
checkOpertorEqToSelf(
@@ -2191,7 +2174,7 @@ class TestClass : public TestFixture {
" s = strdup(b.s);\n"
" return *this;\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqToSelf5() {
@@ -2211,7 +2194,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2228,7 +2211,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2245,7 +2228,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2262,7 +2245,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2279,7 +2262,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2296,7 +2279,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2313,7 +2296,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2330,7 +2313,7 @@ class TestClass : public TestFixture {
" return *this;\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2348,7 +2331,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2366,7 +2349,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2384,7 +2367,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2402,7 +2385,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2420,7 +2403,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2438,7 +2421,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2456,7 +2439,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2474,7 +2457,7 @@ class TestClass : public TestFixture {
" }\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkOpertorEqToSelf(
"struct A {\n"
@@ -2486,7 +2469,7 @@ class TestClass : public TestFixture {
" s = strdup(a.s);\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqToSelf6() {
@@ -2505,7 +2488,7 @@ class TestClass : public TestFixture {
"private:\n"
" char * data;\n"
"};");
- ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2522,7 +2505,7 @@ class TestClass : public TestFixture {
" strcpy(data, a.data);\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2538,7 +2521,7 @@ class TestClass : public TestFixture {
"private:\n"
" char * data;\n"
"};");
- ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
checkOpertorEqToSelf(
"class A\n"
@@ -2555,7 +2538,7 @@ class TestClass : public TestFixture {
" *data = *a.data;\n"
" return *this;\n"
"};");
- ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str());
}
void operatorEqToSelf7() {
@@ -2572,7 +2555,7 @@ class TestClass : public TestFixture {
" return assign(a);\n"
" }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqToSelf8() {
@@ -2591,7 +2574,7 @@ class TestClass : public TestFixture {
"{\n"
" return copy(in);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void operatorEqToSelf9() {
@@ -2610,15 +2593,12 @@ class TestClass : public TestFixture {
"{\n"
" return Foo::operator=(&other);\n"
"}");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
// Check that base classes have virtual destructors
#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)
void checkVirtualDestructor_(const char* file, int line, const char code[], bool inconclusive = false) {
- // Clear the error log
- errout.str("");
-
const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, inconclusive).severity(Severity::warning).build();
Preprocessor preprocessor(s);
@@ -2639,12 +2619,12 @@ class TestClass : public TestFixture {
checkVirtualDestructor("class Derived : public Base { };\n"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkVirtualDestructor("class Derived : Base { };\n"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void virtualDestructor2() {
@@ -2654,25 +2634,25 @@ class TestClass : public TestFixture {
"class Derived : public Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("class Base { };\n"
"class Derived : protected Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("class Base { };\n"
"class Derived : private Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
checkVirtualDestructor("class Base { };\n"
"class Derived : Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// #9104
checkVirtualDestructor("struct A\n"
@@ -2693,7 +2673,7 @@ class TestClass : public TestFixture {
" Base* p = new Derived();\n"
" delete p;\n"
"}");
- ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("using namespace std;\n"
"struct A\n"
@@ -2714,7 +2694,7 @@ class TestClass : public TestFixture {
" Base* p = new Derived();\n"
" delete p;\n"
"}");
- ASSERT_EQUALS("[test.cpp:8]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:8]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
}
void virtualDestructor3() {
@@ -2724,19 +2704,19 @@ class TestClass : public TestFixture {
"class Derived : public Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : protected Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
}
void virtualDestructor4() {
@@ -2746,13 +2726,13 @@ class TestClass : public TestFixture {
"class Derived : public Base { };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : private Fred, public Base { };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
}
void virtualDestructor5() {
@@ -2762,13 +2742,13 @@ class TestClass : public TestFixture {
"class Derived : public Base { public: ~Derived() {} };"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}"
"Base *base = new Derived;\n"
"delete base;");
- ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
+ ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str());
}
void virtualDestructor6() {
@@ -2777,7 +2757,7 @@ class TestClass : public TestFixture {
checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : public Base { public: ~Derived() { (void)11; } };");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void virtualDestructorProtected() {
@@ -2794,7 +2774,7 @@ class TestClass : public TestFixture {
"public:\n"
" ~B() { int a; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
}
void virtualDestructorInherited() {
@@ -2815,7 +2795,7 @@ class TestClass : public TestFixture {
"public:\n"
" ~B() { int a; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// class A inherits virtual destructor from struct Base -> no error
// also notice that public is not given, but destructor is public, because
@@ -2833,7 +2813,7 @@ class TestClass : public TestFixture {
"public:\n"
" ~B() { int a; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Unknown Base class -> it could have virtual destructor, so ignore
checkVirtualDestructor("class A : private Base\n"
@@ -2847,7 +2827,7 @@ class TestClass : public TestFixture {
"public:\n"
" ~B() { int a; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// Virtual destructor is inherited -> no error
checkVirtualDestructor("class Base2\n"
@@ -2868,7 +2848,7 @@ class TestClass : public TestFixture {
"public:\n"
" ~B() { int a; }\n"
"};");
- ASSERT_EQUALS("", errout.str());
+ ASSERT_EQUALS("", errout_str());
// class A doesn't inherit virtual destructor from class Base -> error
checkVirtualDestructor("class Base\n"
@@ -2888,7 +2868,7 @@ class TestClass : public TestFixture {
" ~B() { int a; }\n"
"};");
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\n",
- "", errout.str());
+ "", errout_str());
}
void virtualDestructorTemplate() {
@@ -2909,7 +2889,7 @@ class TestClass : public TestFixture {
"};\n"
"\n"
"AA