|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (c) 2019 The Bitcoin Core developers |
| 4 | +# Distributed under the MIT software license, see the accompanying |
| 5 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 6 | +# |
| 7 | + |
| 8 | +export LC_ALL=C |
| 9 | + |
| 10 | +ENABLED_CHECKS=( |
| 11 | + "Class '.*' has a constructor with 1 argument that is not explicit." |
| 12 | + "Struct '.*' has a constructor with 1 argument that is not explicit." |
| 13 | +) |
| 14 | + |
| 15 | +IGNORED_WARNINGS=( |
| 16 | + "src/arith_uint256.h:.* Class 'arith_uint256' has a constructor with 1 argument that is not explicit." |
| 17 | + "src/arith_uint256.h:.* Class 'base_uint < 256 >' has a constructor with 1 argument that is not explicit." |
| 18 | + "src/arith_uint256.h:.* Class 'base_uint' has a constructor with 1 argument that is not explicit." |
| 19 | + "src/coins.h:.* Class 'CCoinsViewBacked' has a constructor with 1 argument that is not explicit." |
| 20 | + "src/coins.h:.* Class 'CCoinsViewCache' has a constructor with 1 argument that is not explicit." |
| 21 | + "src/coins.h:.* Class 'CCoinsViewCursor' has a constructor with 1 argument that is not explicit." |
| 22 | + "src/net.h:.* Class 'CNetMessage' has a constructor with 1 argument that is not explicit." |
| 23 | + "src/policy/feerate.h:.* Class 'CFeeRate' has a constructor with 1 argument that is not explicit." |
| 24 | + "src/prevector.h:.* Class 'const_iterator' has a constructor with 1 argument that is not explicit." |
| 25 | + "src/prevector.h:.* Class 'const_reverse_iterator' has a constructor with 1 argument that is not explicit." |
| 26 | + "src/prevector.h:.* Class 'iterator' has a constructor with 1 argument that is not explicit." |
| 27 | + "src/prevector.h:.* Class 'reverse_iterator' has a constructor with 1 argument that is not explicit." |
| 28 | + "src/primitives/block.h:.* Class 'CBlock' has a constructor with 1 argument that is not explicit." |
| 29 | + "src/primitives/transaction.h:.* Class 'CTransaction' has a constructor with 1 argument that is not explicit." |
| 30 | + "src/protocol.h:.* Class 'CMessageHeader' has a constructor with 1 argument that is not explicit." |
| 31 | + "src/qt/guiutil.h:.* Class 'ItemDelegate' has a constructor with 1 argument that is not explicit." |
| 32 | + "src/rpc/util.h:.* Struct 'RPCResults' has a constructor with 1 argument that is not explicit." |
| 33 | + "src/rpc/util.h:.* style: Struct 'UniValueType' has a constructor with 1 argument that is not explicit." |
| 34 | + "src/script/descriptor.cpp:.* Class 'AddressDescriptor' has a constructor with 1 argument that is not explicit." |
| 35 | + "src/script/descriptor.cpp:.* Class 'ComboDescriptor' has a constructor with 1 argument that is not explicit." |
| 36 | + "src/script/descriptor.cpp:.* Class 'ConstPubkeyProvider' has a constructor with 1 argument that is not explicit." |
| 37 | + "src/script/descriptor.cpp:.* Class 'PKDescriptor' has a constructor with 1 argument that is not explicit." |
| 38 | + "src/script/descriptor.cpp:.* Class 'PKHDescriptor' has a constructor with 1 argument that is not explicit." |
| 39 | + "src/script/descriptor.cpp:.* Class 'RawDescriptor' has a constructor with 1 argument that is not explicit." |
| 40 | + "src/script/descriptor.cpp:.* Class 'SHDescriptor' has a constructor with 1 argument that is not explicit." |
| 41 | + "src/script/descriptor.cpp:.* Class 'WPKHDescriptor' has a constructor with 1 argument that is not explicit." |
| 42 | + "src/script/descriptor.cpp:.* Class 'WSHDescriptor' has a constructor with 1 argument that is not explicit." |
| 43 | + "src/script/script.h:.* Class 'CScript' has a constructor with 1 argument that is not explicit." |
| 44 | + "src/script/standard.h:.* Class 'CScriptID' has a constructor with 1 argument that is not explicit." |
| 45 | + "src/support/allocators/secure.h:.* Struct 'secure_allocator < char >' has a constructor with 1 argument that is not explicit." |
| 46 | + "src/support/allocators/secure.h:.* Struct 'secure_allocator < RNGState >' has a constructor with 1 argument that is not explicit." |
| 47 | + "src/support/allocators/secure.h:.* Struct 'secure_allocator < unsigned char >' has a constructor with 1 argument that is not explicit." |
| 48 | + "src/support/allocators/zeroafterfree.h:.* Struct 'zero_after_free_allocator < char >' has a constructor with 1 argument that is not explicit." |
| 49 | + "src/test/checkqueue_tests.cpp:.* Struct 'FailingCheck' has a constructor with 1 argument that is not explicit." |
| 50 | + "src/test/checkqueue_tests.cpp:.* Struct 'MemoryCheck' has a constructor with 1 argument that is not explicit." |
| 51 | + "src/test/checkqueue_tests.cpp:.* Struct 'UniqueCheck' has a constructor with 1 argument that is not explicit." |
| 52 | + "src/wallet/db.h:.* Class 'BerkeleyEnvironment' has a constructor with 1 argument that is not explicit." |
| 53 | +) |
| 54 | + |
| 55 | +if ! command -v cppcheck > /dev/null; then |
| 56 | + echo "Skipping cppcheck linting since cppcheck is not installed. Install by running \"apt install cppcheck\"" |
| 57 | + exit 0 |
| 58 | +fi |
| 59 | + |
| 60 | +function join_array { |
| 61 | + local IFS="$1" |
| 62 | + shift |
| 63 | + echo "$*" |
| 64 | +} |
| 65 | + |
| 66 | +ENABLED_CHECKS_REGEXP=$(join_array "|" "${ENABLED_CHECKS[@]}") |
| 67 | +IGNORED_WARNINGS_REGEXP=$(join_array "|" "${IGNORED_WARNINGS[@]}") |
| 68 | +WARNINGS=$(git ls-files -- "*.cpp" "*.h" ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" | \ |
| 69 | + xargs cppcheck --enable=all -j "$(getconf _NPROCESSORS_ONLN)" --language=c++ --std=c++11 --template=gcc -D__cplusplus -DCLIENT_VERSION_BUILD -DCLIENT_VERSION_IS_RELEASE -DCLIENT_VERSION_MAJOR -DCLIENT_VERSION_MINOR -DCLIENT_VERSION_REVISION -DCOPYRIGHT_YEAR -DDEBUG -DHAVE_WORKING_BOOST_SLEEP_FOR -I src/ -q 2>&1 | sort -u | \ |
| 70 | + grep -E "${ENABLED_CHECKS_REGEXP}" | \ |
| 71 | + grep -vE "${IGNORED_WARNINGS_REGEXP}") |
| 72 | +if [[ ${WARNINGS} != "" ]]; then |
| 73 | + echo "${WARNINGS}" |
| 74 | + echo |
| 75 | + echo "Advice not applicable in this specific case? Add an exception by updating" |
| 76 | + echo "IGNORED_WARNINGS in $0" |
| 77 | + # Uncomment to enforce the developer note policy "By default, declare single-argument constructors `explicit`" |
| 78 | + # exit 1 |
| 79 | +fi |
| 80 | +exit 0 |
0 commit comments