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.
This commit is contained in:
amai2012 2020-10-23 11:58:25 +02:00 committed by GitHub
parent d7a8e25d92
commit 2fa837c716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 4 deletions

View File

@ -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

View File

@ -0,0 +1,6 @@
struct Dummy {
int x;
};
void func() {
static Dummy dummy;
}

View File

@ -0,0 +1,6 @@
struct Dummy {
int x;
};
void func() {
static const Dummy dummy;
}

View File

@ -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')