diff --git a/.clang-tidy b/.clang-tidy
index 62047bd3966..e1032aaa5f3 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -50,10 +50,12 @@ Checks: >
-modernize-type-traits,
-modernize-use-designated-initializers,
-modernize-use-nodiscard,
+ -modernize-use-scoped-lock,
-modernize-use-trailing-return-type,
-performance-avoid-endl,
-performance-inefficient-string-concatenation,
-performance-no-automatic-move,
+ -portability-avoid-pragma-once,
-portability-simd-intrinsics,
-portability-std-allocator-const,
-readability-avoid-nested-conditional-operator,
@@ -68,7 +70,8 @@ Checks: >
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-suspicious-call-argument,
- -readability-uppercase-literal-suffix
+ -readability-uppercase-literal-suffix,
+ -readability-use-concise-preprocessor-directives
WarningsAsErrors: '*'
HeaderFilterRegex: '(cli|gui|frontend|lib|oss-fuzz|test|triage)\/[a-z_]+\.h'
ExcludeHeaderFilterRegex: 'ui_.*.h'
@@ -77,3 +80,5 @@ CheckOptions:
value: '1'
- key: readability-simplify-boolean-expr.SimplifyDeMorgan
value: '0'
+ - key: modernize-use-trailing-return-type.TransformFunctions
+ value: false
diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml
index f2c4f2cdd1b..06bd57e69d5 100644
--- a/.github/workflows/asan.yml
+++ b/.github/workflows/asan.yml
@@ -53,7 +53,7 @@ jobs:
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
- sudo ./llvm.sh 20
+ sudo ./llvm.sh 21
- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v4
@@ -76,8 +76,8 @@ jobs:
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DUSE_QT6=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
- CC: clang-20
- CXX: clang++-20
+ CC: clang-21
+ CXX: clang++-21
- name: Build cppcheck
run: |
diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml
index e9c486cc4f4..c88c6f8238f 100644
--- a/.github/workflows/clang-tidy.yml
+++ b/.github/workflows/clang-tidy.yml
@@ -43,8 +43,8 @@ jobs:
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
- sudo ./llvm.sh 20
- sudo apt-get install -y clang-tidy-20
+ sudo ./llvm.sh 21
+ sudo apt-get install -y clang-tidy-21
- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v4
@@ -57,14 +57,14 @@ jobs:
- name: Verify clang-tidy configuration
run: |
- clang-tidy-20 --verify-config
+ clang-tidy-21 --verify-config
- name: Prepare CMake
run: |
cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCPPCHK_GLIBCXX_DEBUG=Off -DWARNINGS_ARE_ERRORS=On
env:
- CC: clang-20
- CXX: clang++-20
+ CC: clang-21
+ CXX: clang++-21
- name: Prepare CMake dependencies
run: |
diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml
index 65e5ca5f9f1..6e5332c089d 100644
--- a/.github/workflows/iwyu.yml
+++ b/.github/workflows/iwyu.yml
@@ -215,13 +215,13 @@ jobs:
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
- sudo ./llvm.sh 20
- sudo apt-get install -y clang-tools-20
+ sudo ./llvm.sh 21
+ sudo apt-get install -y clang-tools-21
- name: Install libc++
if: matrix.stdlib == 'libc++'
run: |
- sudo apt-get install -y libc++-20-dev
+ sudo apt-get install -y libc++-21-dev
- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v4
@@ -237,8 +237,8 @@ jobs:
# TODO: why does it build dmake in the next step?
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.use_libcxx }}
env:
- CC: clang-20
- CXX: clang++-20
+ CC: clang-21
+ CXX: clang++-21
- name: Prepare CMake dependencies
run: |
@@ -255,7 +255,7 @@ jobs:
- name: clang-include-cleaner
run: |
# TODO: run multi-threaded
- find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-20 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1
+ find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-21 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1
- uses: actions/upload-artifact@v4
if: success() || failure()
diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml
index 4347e5e1b98..8109e8c1ac5 100644
--- a/.github/workflows/tsan.yml
+++ b/.github/workflows/tsan.yml
@@ -53,7 +53,7 @@ jobs:
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
- sudo ./llvm.sh 20
+ sudo ./llvm.sh 21
- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v4
@@ -75,8 +75,8 @@ jobs:
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DUSE_QT6=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -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 -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
- CC: clang-20
- CXX: clang++-20
+ CC: clang-21
+ CXX: clang++-21
- name: Build cppcheck
run: |
diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml
index 11dc26a8ec3..e1f64f25040 100644
--- a/.github/workflows/ubsan.yml
+++ b/.github/workflows/ubsan.yml
@@ -53,7 +53,7 @@ jobs:
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
- sudo ./llvm.sh 20
+ sudo ./llvm.sh 21
- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v4
@@ -76,8 +76,8 @@ jobs:
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DUSE_QT6=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
- CC: clang-20
- CXX: clang++-20
+ CC: clang-21
+ CXX: clang++-21
- name: Build cppcheck
run: |
diff --git a/clang-tidy.md b/clang-tidy.md
index 59d28dbaa3d..72df0375ca1 100644
--- a/clang-tidy.md
+++ b/clang-tidy.md
@@ -33,7 +33,6 @@ These are coding guidelines we do not follow. Some of the checks might be explic
`readability-braces-around-statements`
`readability-isolate-declaration`
-`modernize-use-trailing-return-type`
`readability-uppercase-literal-suffix`
`readability-identifier-length`
@@ -112,7 +111,11 @@ Also reports a false positive about templates which deduce the array length: htt
`misc-include-cleaner`
-We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as the findings of the include checkers still need to be reviewed manually before applying them.
+We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as the findings of the include checkers still need to be reviewed manually before applying them.
+
+`readability-use-concise-preprocessor-directives`
+
+Does not improve the readability.
`bugprone-branch-clone`
`modernize-return-braced-init-list`
@@ -126,6 +129,7 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
`readability-avoid-nested-conditional-operator`
`modernize-use-designated-initializers`
`readability-enum-initial-value`
+`modernize-use-trailing-return-type`
To be evaluated (need to remove exclusion).
@@ -144,9 +148,14 @@ To be evaluated (need to enable explicitly).
`modernize-type-traits`
`modernize-use-nodiscard`
+`modernize-use-scoped-lock`
These apply to codebases which use later standards then C++11 (C++17 is used when building with Qt6) so we cannot simply apply them.
+`portability-avoid-pragma-once`
+
+We are not interested in this.
+
### Disabled for performance reasons
`portability-std-allocator-const`
diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp
index af9041bd555..b839e179750 100644
--- a/cli/processexecutor.cpp
+++ b/cli/processexecutor.cpp
@@ -127,12 +127,12 @@ namespace {
const ssize_t bytes_written = write(mWpipe, data, to_write);
if (bytes_written <= 0) {
const int err = errno;
- std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
+ std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast(type) << ": " << std::strerror(err) << std::endl;
std::exit(EXIT_FAILURE);
}
// TODO: write until everything is written
if (bytes_written != to_write) {
- std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
+ std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast(type) << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
std::exit(EXIT_FAILURE);
}
}
diff --git a/cli/signalhandler.cpp b/cli/signalhandler.cpp
index 1b6fb445b49..a8f3d898b71 100644
--- a/cli/signalhandler.cpp
+++ b/cli/signalhandler.cpp
@@ -58,7 +58,7 @@
#ifdef __USE_DYNAMIC_STACK_SIZE
static constexpr size_t MYSTACKSIZE = (16*1024)+32768; // wild guess about a reasonable buffer
#else
-static constexpr size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
+static constexpr size_t MYSTACKSIZE = (16*1024)+SIGSTKSZ; // wild guess about a reasonable buffer
#endif
static char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler
static bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper()
diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake
index bdbb5feca4c..e9a9148c6fe 100644
--- a/cmake/clang_tidy.cmake
+++ b/cmake/clang_tidy.cmake
@@ -11,7 +11,7 @@ if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(STATUS "Cannot use non-Clang compiler with clang-tidy when precompiled headers are enabled - skipping 'run-clang-tidy'/'run-clang-tidy-csa' target generation")
endif()
else()
- set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-20 run-clang-tidy-19 run-clang-tidy-18 run-clang-tidy-17 run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8)
+ set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-21 run-clang-tidy-20 run-clang-tidy-19 run-clang-tidy-18 run-clang-tidy-17 run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8)
endif()
if(RUN_CLANG_TIDY_NAMES)
@@ -32,10 +32,9 @@ if(RUN_CLANG_TIDY_NAMES)
# clang-analyzer-cplusplus.NewDelete
# clang-analyzer-core.NullDereference
# clang-analyzer-unix.Stream
- # clang-analyzer-optin.cplusplus.UninitializedObject - false positives with unnamed fields - see https://github.com/llvm/llvm-project/issues/132001
# clang-analyzer-alpha.clone.CloneChecker
# clang-analyzer-alpha.webkit.* - we are not interested in these
- set(CLANG_TIDY_CSA_CONFIG "-config={InheritParentConfig: true, Checks: '-*,clang-analyzer-*,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-cplusplus.NewDelete,-clang-analyzer-core.NullDereference,-clang-analyzer-unix.Stream,-clang-analyzer-optin.cplusplus.UninitializedObject,-clang-analyzer-alpha.clone.CloneChecker,-clang-analyzer-alpha.webkit.*'}")
+ set(CLANG_TIDY_CSA_CONFIG "-config={InheritParentConfig: true, Checks: '-*,clang-analyzer-*,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-cplusplus.NewDelete,-clang-analyzer-core.NullDereference,-clang-analyzer-unix.Stream,-clang-analyzer-alpha.clone.CloneChecker,-clang-analyzer-alpha.webkit.*'}")
if (ENABLE_CSA_ALPHA)
set(CLANG_TIDY_CSA_ALPHA_OPTS "-allow-enabling-alpha-checkers" "-extra-arg=-Xclang" "-extra-arg=-analyzer-config" "-extra-arg=-Xclang" "-extra-arg=aggressive-binary-operation-simplification=true")
endif()
diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake
index ada39cea21f..be906e46afe 100644
--- a/cmake/compileroptions.cmake
+++ b/cmake/compileroptions.cmake
@@ -122,6 +122,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
add_compile_options(-Wno-sign-compare)
+ add_compile_options_safe(-Wno-ms-bitfield-padding) # TODO: fix this
# these cannot be fixed properly without adopting later C++ standards
add_compile_options_safe(-Wno-unsafe-buffer-usage)
@@ -130,6 +131,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# can only be partially addressed
add_compile_options(-Wno-padded)
+ add_compile_options_safe(-Wno-nrvo)
# no need for C++98 compatibility
add_compile_options(-Wno-c++98-compat)
diff --git a/gui/cppchecklibrarydata.cpp b/gui/cppchecklibrarydata.cpp
index f7a306a6b12..637ad841580 100644
--- a/gui/cppchecklibrarydata.cpp
+++ b/gui/cppchecklibrarydata.cpp
@@ -33,12 +33,12 @@
const unsigned int CppcheckLibraryData::Function::Arg::ANY = ~0U;
const unsigned int CppcheckLibraryData::Function::Arg::VARIADIC = ~1U;
-static std::string unhandledElement(const QXmlStreamReader &xmlReader)
+NORETURN static void unhandledElement(const QXmlStreamReader &xmlReader)
{
throw std::runtime_error(QObject::tr("line %1: Unhandled element %2").arg(xmlReader.lineNumber()).arg(xmlReader.name().toString()).toStdString());
}
-static std::string mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, const QString& attributeName)
+NORETURN static void mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, const QString& attributeName)
{
throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'")
.arg(xmlReader.lineNumber())
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 13193957258..d4dbc69bf9d 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -2244,12 +2244,12 @@ static int getVersion(const QString& nameWithVersion) {
}
else if (c == '.') {
++dot;
- ret = ret * 1000 + v;
+ ret = (ret * 1000) + v;
v = 0;
} else if (c >= '0' && c <= '9')
- v = v * 10 + (c.toLatin1() - '0');
+ v = (v * 10) + (c.toLatin1() - '0');
}
- ret = ret * 1000 + v;
+ ret = (ret * 1000) + v;
while (dot < 2) {
++dot;
ret *= 1000;
diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp
index 47034019920..8a9a564dd24 100644
--- a/lib/clangimport.cpp
+++ b/lib/clangimport.cpp
@@ -997,7 +997,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
--addrIndex;
const std::string addr = mExtTokens[addrIndex];
std::string name = unquote(getSpelling());
- Token *reftok = addtoken(tokenList, name.empty() ? "" : std::move(name));
+ Token *reftok = addtoken(tokenList, name.empty() ? "" : name);
mData->ref(addr, reftok);
return reftok;
}
diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp
index a7198e33007..6ec2df39b57 100644
--- a/lib/valueflow.cpp
+++ b/lib/valueflow.cpp
@@ -547,7 +547,7 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
if (currentBitfieldAlloc == 0) {
bits = n * charBit;
} else {
- bits = currentBitfieldAlloc * charBit - currentBitCount;
+ bits = (currentBitfieldAlloc * charBit) - currentBitCount;
}
}
if (bits > 0) {
@@ -570,7 +570,7 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
n *= dim;
size_t padding = (a - (total % a)) % a;
if (currentBitCount > 0) {
- bool fitsInBitfield = currentBitCount + n * charBit <= currentBitfieldAlloc * charBit;
+ bool fitsInBitfield = currentBitCount + (n * charBit) <= currentBitfieldAlloc * charBit;
bool isAligned = currentBitCount % (charBit * a) == 0;
if (vt2.isIntegral() && fitsInBitfield && isAligned) {
currentBitCount += charBit * n;
@@ -5857,7 +5857,7 @@ static void valueFlowSubFunction(const TokenList& tokenlist,
v.errorPath.emplace_back(argtok,
"Calling function '" + calledFunction->name() + "', " + nr + " argument '" +
argtok->expressionString() + "' value is " + v.infoString());
- v.path = 256 * v.path + id % 256;
+ v.path = (256 * v.path) + (id % 256);
// Change scope of lifetime values
if (v.isLifetimeValue())
v.lifetimeScope = ValueFlow::Value::LifetimeScope::SubFunction;
diff --git a/test/fixture.h b/test/fixture.h
index 7be1d2d9237..5e0244983b0 100644
--- a/test/fixture.h
+++ b/test/fixture.h
@@ -79,8 +79,10 @@ class TestFixture : public ErrorLogger {
void assertEquals(const char* const filename, const unsigned int linenr, const T& expected, const T& actual, const std::string& msg = "") const {
if (expected != actual) {
std::ostringstream expectedStr;
+ // NOLINTNEXTLINE(bugprone-unintended-char-ostream-output) - chars being treated as integers is acceptable here
expectedStr << expected;
std::ostringstream actualStr;
+ // NOLINTNEXTLINE(bugprone-unintended-char-ostream-output) - chars being treated as integers is acceptable here
actualStr << actual;
assertFailure(filename, linenr, expectedStr.str(), actualStr.str(), msg);
diff --git a/test/testexecutor.cpp b/test/testexecutor.cpp
index 33fb454f5a4..4f952a4004d 100644
--- a/test/testexecutor.cpp
+++ b/test/testexecutor.cpp
@@ -38,7 +38,7 @@ class DummyExecutor : public Executor
: Executor(files, fileSettings, settings, suppressions, errorLogger)
{}
- unsigned int check() override
+ NORETURN unsigned int check() override
{
throw std::runtime_error("not implemented");
}
diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp
index 65ad80e802c..1796d54e68c 100644
--- a/test/testsimplifytemplate.cpp
+++ b/test/testsimplifytemplate.cpp
@@ -4683,43 +4683,43 @@ class TestSimplifyTemplate : public TestFixture {
}
void template_enum() {
- const char code1[] = "template \n"
- "struct Unconst {\n"
- " typedef T type;\n"
- "};\n"
- "template \n"
- "struct Unconst {\n"
- " typedef T type;\n"
- "};\n"
- "template \n"
- "struct Unconst {\n"
- " typedef T& type;\n"
- "};\n"
- "template \n"
- "struct Unconst {\n"
- " typedef T* type;\n"
- "};\n"
- "template \n"
- "struct type_equal {\n"
- " enum { value = 0 };\n"
- "};\n"
- "template \n"
- "struct type_equal {\n"
- " enum { value = 1 };\n"
- "};\n"
- "template\n"
- "struct template_is_const\n"
- "{\n"
- " enum {value = !type_equal::type>::value };\n"
- "};";
- const char exp1[] = "template < class T > struct Unconst { } ; "
- "template < class T > struct Unconst < const T > { } ; "
- "template < class T > struct Unconst < const T & > { } ; "
- "template < class T > struct Unconst < T * const > { } ; "
- "template < class T1 , class T2 > struct type_equal { enum Anonymous0 { value = 0 } ; } ; "
- "template < class T > struct type_equal < T , T > { enum Anonymous1 { value = 1 } ; } ; "
- "template < class T > struct template_is_const { enum Anonymous2 { value = ! type_equal < T , Unconst < T > :: type > :: value } ; } ;";
- ASSERT_EQUALS(exp1, tok(code1));
+ const char code[] = "template \n"
+ "struct Unconst {\n"
+ " typedef T type;\n"
+ "};\n"
+ "template \n"
+ "struct Unconst {\n"
+ " typedef T type;\n"
+ "};\n"
+ "template \n"
+ "struct Unconst {\n"
+ " typedef T& type;\n"
+ "};\n"
+ "template \n"
+ "struct Unconst {\n"
+ " typedef T* type;\n"
+ "};\n"
+ "template \n"
+ "struct type_equal {\n"
+ " enum { value = 0 };\n"
+ "};\n"
+ "template \n"
+ "struct type_equal {\n"
+ " enum { value = 1 };\n"
+ "};\n"
+ "template\n"
+ "struct template_is_const\n"
+ "{\n"
+ " enum {value = !type_equal::type>::value };\n"
+ "};";
+ const char exp[] = "template < class T > struct Unconst { } ; "
+ "template < class T > struct Unconst < const T > { } ; "
+ "template < class T > struct Unconst < const T & > { } ; "
+ "template < class T > struct Unconst < T * const > { } ; "
+ "template < class T1 , class T2 > struct type_equal { enum Anonymous0 { value = 0 } ; } ; "
+ "template < class T > struct type_equal < T , T > { enum Anonymous1 { value = 1 } ; } ; "
+ "template < class T > struct template_is_const { enum Anonymous2 { value = ! type_equal < T , Unconst < T > :: type > :: value } ; } ;";
+ ASSERT_EQUALS(exp, tok(code));
}
void template_default_parameter() {
diff --git a/test/testvarid.cpp b/test/testvarid.cpp
index 27efdeed0d1..d509ece2f13 100644
--- a/test/testvarid.cpp
+++ b/test/testvarid.cpp
@@ -3307,31 +3307,31 @@ class TestVarID : public TestFixture {
}
void varid_trailing_return1() { // #8889
- const char code1[] = "struct Fred {\n"
- " auto foo(const Fred & other) -> Fred &;\n"
- " auto bar(const Fred & other) -> Fred & {\n"
- " return *this;\n"
- " }\n"
- "};\n"
- "auto Fred::foo(const Fred & other) -> Fred & {\n"
- " return *this;\n"
- "}";
- const char exp1[] = "1: struct Fred {\n"
- "2: auto foo ( const Fred & other@1 ) . Fred & ;\n"
- "3: auto bar ( const Fred & other@2 ) . Fred & {\n"
- "4: return * this ;\n"
- "5: }\n"
- "6: } ;\n"
- "7: auto Fred :: foo ( const Fred & other@3 ) . Fred & {\n"
- "8: return * this ;\n"
- "9: }\n";
- ASSERT_EQUALS(exp1, tokenize(code1));
+ const char code[] = "struct Fred {\n"
+ " auto foo(const Fred & other) -> Fred &;\n"
+ " auto bar(const Fred & other) -> Fred & {\n"
+ " return *this;\n"
+ " }\n"
+ "};\n"
+ "auto Fred::foo(const Fred & other) -> Fred & {\n"
+ " return *this;\n"
+ "}";
+ const char exp[] = "1: struct Fred {\n"
+ "2: auto foo ( const Fred & other@1 ) . Fred & ;\n"
+ "3: auto bar ( const Fred & other@2 ) . Fred & {\n"
+ "4: return * this ;\n"
+ "5: }\n"
+ "6: } ;\n"
+ "7: auto Fred :: foo ( const Fred & other@3 ) . Fred & {\n"
+ "8: return * this ;\n"
+ "9: }\n";
+ ASSERT_EQUALS(exp, tokenize(code));
}
void varid_trailing_return2() { // #9066
- const char code1[] = "auto func(int arg) -> bar::quux {}";
- const char exp1[] = "1: auto func ( int arg@1 ) . bar :: quux { }\n";
- ASSERT_EQUALS(exp1, tokenize(code1));
+ const char code[] = "auto func(int arg) -> bar::quux {}";
+ const char exp[] = "1: auto func ( int arg@1 ) . bar :: quux { }\n";
+ ASSERT_EQUALS(exp, tokenize(code));
}
void varid_trailing_return3() { // #11423
@@ -3347,15 +3347,15 @@ class TestVarID : public TestFixture {
}
void varid_parameter_pack() { // #9383
- const char code1[] = "template \n"
- "void func(Rest... parameters) {\n"
- " foo(parameters...);\n"
- "}\n";
- const char exp1[] = "1: template < typename ... Rest >\n"
- "2: void func ( Rest ... parameters@1 ) {\n"
- "3: foo ( parameters@1 ... ) ;\n"
- "4: }\n";
- ASSERT_EQUALS(exp1, tokenize(code1));
+ const char code[] = "template \n"
+ "void func(Rest... parameters) {\n"
+ " foo(parameters...);\n"
+ "}\n";
+ const char exp[] = "1: template < typename ... Rest >\n"
+ "2: void func ( Rest ... parameters@1 ) {\n"
+ "3: foo ( parameters@1 ... ) ;\n"
+ "4: }\n";
+ ASSERT_EQUALS(exp, tokenize(code));
}
void varid_for_auto_cpp17() {
@@ -3365,23 +3365,23 @@ class TestVarID : public TestFixture {
" }\n"
" x+y+z;\n"
"}";
- const char exp1[] = "1: void f ( ) {\n"
- "2: for ( auto [ x@1 , y@2 , z@3 ] : xyz ) {\n"
- "3: x@1 + y@2 + z@3 ;\n"
- "4: }\n"
- "5: x + y + z ;\n"
- "6: }\n";
- ASSERT_EQUALS(exp1, tokenize(code));
+ const char exp[] = "1: void f ( ) {\n"
+ "2: for ( auto [ x@1 , y@2 , z@3 ] : xyz ) {\n"
+ "3: x@1 + y@2 + z@3 ;\n"
+ "4: }\n"
+ "5: x + y + z ;\n"
+ "6: }\n";
+ ASSERT_EQUALS(exp, tokenize(code));
}
void varid_not() { // #9689 'not x'
- const char code1[] = "void foo(int x) const {\n"
- " if (not x) {}\n"
- "}";
- const char exp1[] = "1: void foo ( int x@1 ) const {\n"
- "2: if ( ! x@1 ) { }\n"
- "3: }\n";
- ASSERT_EQUALS(exp1, tokenize(code1));
+ const char code[] = "void foo(int x) const {\n"
+ " if (not x) {}\n"
+ "}";
+ const char exp[] = "1: void foo ( int x@1 ) const {\n"
+ "2: if ( ! x@1 ) { }\n"
+ "3: }\n";
+ ASSERT_EQUALS(exp, tokenize(code));
}
void varid_declInIfCondition() {
@@ -3441,26 +3441,26 @@ class TestVarID : public TestFixture {
}
void varid_globalScope() {
- const char code1[] = "int a[5];\n"
- "namespace Z { struct B { int a[5]; } b; }\n"
- "void f() {\n"
- " int a[5];\n"
- " memset(a, 123, 5);\n"
- " memset(::a, 123, 5);\n"
- " memset(Z::b.a, 123, 5);\n"
- " memset(::Z::b.a, 123, 5);\n"
- "}";
+ const char code[] = "int a[5];\n"
+ "namespace Z { struct B { int a[5]; } b; }\n"
+ "void f() {\n"
+ " int a[5];\n"
+ " memset(a, 123, 5);\n"
+ " memset(::a, 123, 5);\n"
+ " memset(Z::b.a, 123, 5);\n"
+ " memset(::Z::b.a, 123, 5);\n"
+ "}";
- const char exp1[] = "1: int a@1 [ 5 ] ;\n"
- "2: namespace Z { struct B { int a@2 [ 5 ] ; } ; struct B b@3 ; }\n"
- "3: void f ( ) {\n"
- "4: int a@4 [ 5 ] ;\n"
- "5: memset ( a@4 , 123 , 5 ) ;\n"
- "6: memset ( :: a@1 , 123 , 5 ) ;\n"
- "7: memset ( Z :: b@3 . a , 123 , 5 ) ;\n"
- "8: memset ( :: Z :: b@3 . a , 123 , 5 ) ;\n"
- "9: }\n";
- ASSERT_EQUALS(exp1, tokenize(code1));
+ const char exp[] = "1: int a@1 [ 5 ] ;\n"
+ "2: namespace Z { struct B { int a@2 [ 5 ] ; } ; struct B b@3 ; }\n"
+ "3: void f ( ) {\n"
+ "4: int a@4 [ 5 ] ;\n"
+ "5: memset ( a@4 , 123 , 5 ) ;\n"
+ "6: memset ( :: a@1 , 123 , 5 ) ;\n"
+ "7: memset ( Z :: b@3 . a , 123 , 5 ) ;\n"
+ "8: memset ( :: Z :: b@3 . a , 123 , 5 ) ;\n"
+ "9: }\n";
+ ASSERT_EQUALS(exp, tokenize(code));
}
void varid_function_pointer_args() {