From 2fa837c71624e1bfa02141246497cab4c352fab8 Mon Sep 17 00:00:00 2001 From: amai2012 Date: Fri, 23 Oct 2020 11:58:25 +0200 Subject: [PATCH] threadsafety shall not warn about const vars (in C++11) (#2847) threadsafety shall not warn about const vars (in C++11) For C++03 a new id threadsafety-const was created. --- .github/workflows/CI-unixish.yml | 11 ++++++++--- addons/test/threadsafety/local_static.cpp | 6 ++++++ addons/test/threadsafety/local_static_const.cpp | 6 ++++++ addons/threadsafety.py | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 addons/test/threadsafety/local_static.cpp create mode 100644 addons/test/threadsafety/local_static_const.cpp diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 157f9193e..1cec7346e 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -28,7 +28,7 @@ jobs: - name: Install missing software on macos if: matrix.os == 'macos-latest' run: | - brew install z3 + brew install coreutils z3 - name: Install Qt if: matrix.os == 'ubuntu-latest' @@ -44,7 +44,7 @@ jobs: make -j$(nproc) check cd .. - - name: Unsigned char + - name: Build and test with Unsigned char run: | make clean make -j$(nproc) CXXFLAGS=-funsigned-char testrunner @@ -67,6 +67,11 @@ jobs: - name: Validate run: | make -j$(nproc) validateCFG validatePlatforms + + - name: Test addons + run: | + ./cppcheck --addon=threadsafety addons/test/threadsafety + ./cppcheck --addon=threadsafety --std=c++03 addons/test/threadsafety - name: Build GUI on ubuntu if: matrix.os == 'ubuntu-latest' @@ -112,7 +117,7 @@ jobs: qmake make -j$(nproc) - - name: Fuzzer + - name: Build Fuzzer run: | g++ -fsyntax-only -std=c++11 -Ilib oss-fuzz/*.cpp diff --git a/addons/test/threadsafety/local_static.cpp b/addons/test/threadsafety/local_static.cpp new file mode 100644 index 000000000..433cbaa77 --- /dev/null +++ b/addons/test/threadsafety/local_static.cpp @@ -0,0 +1,6 @@ +struct Dummy { + int x; +}; +void func() { + static Dummy dummy; +} diff --git a/addons/test/threadsafety/local_static_const.cpp b/addons/test/threadsafety/local_static_const.cpp new file mode 100644 index 000000000..12ab715af --- /dev/null +++ b/addons/test/threadsafety/local_static_const.cpp @@ -0,0 +1,6 @@ +struct Dummy { + int x; +}; +void func() { + static const Dummy dummy; +} diff --git a/addons/threadsafety.py b/addons/threadsafety.py index 3faacb0a3..81538a274 100755 --- a/addons/threadsafety.py +++ b/addons/threadsafety.py @@ -20,7 +20,8 @@ def checkstatic(data): else: type = 'variable' if var.isConst: - reportError(var.typeStartToken, 'warning', 'Local constant static ' + type + ' \'' + var.nameToken.str + '\', dangerous if it is initialized in parallel threads', 'threadsafety') + if data.standards.cpp == 'c++03': + reportError(var.typeStartToken, 'warning', 'Local constant static ' + type + ' \'' + var.nameToken.str + '\', dangerous if it is initialized in parallel threads', 'threadsafety-const') else: reportError(var.typeStartToken, 'warning', 'Local static ' + type + ': ' + var.nameToken.str, 'threadsafety')