Skip to content

Commit ad9563f

Browse files
authored
fixed #14267 - fixed compilation with C++17 / use simplecpp::View (#7962)
1 parent 0725556 commit ad9563f

File tree

13 files changed

+116
-29
lines changed

13 files changed

+116
-29
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,60 @@ jobs:
191191
run: |
192192
cmake -S . -B cmake.output_nocli_nogui -G "Unix Makefiles" -DBUILD_GUI=Off
193193
194+
build_cmake_cxxstd:
195+
196+
strategy:
197+
matrix:
198+
os: [ubuntu-22.04, macos-15]
199+
cxxstd: [14, 17]
200+
fail-fast: false # Prefer quick result
201+
202+
runs-on: ${{ matrix.os }}
203+
204+
env:
205+
# TODO: figure out why there are cache misses with PCH enabled
206+
CCACHE_SLOPPINESS: pch_defines,time_macros
207+
208+
steps:
209+
- uses: actions/checkout@v4
210+
with:
211+
persist-credentials: false
212+
213+
- name: ccache
214+
uses: hendrikmuhs/[email protected]
215+
with:
216+
key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }}-${{ matrix.cxxstd }}
217+
218+
- name: Install missing software on ubuntu
219+
if: contains(matrix.os, 'ubuntu')
220+
run: |
221+
sudo apt-get update
222+
sudo apt-get install libxml2-utils
223+
# qt6-tools-dev-tools for lprodump
224+
# qt6-l10n-tools for lupdate
225+
sudo apt-get install qt6-base-dev libqt6charts6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools libglx-dev libgl1-mesa-dev
226+
227+
# coreutils contains "nproc"
228+
- name: Install missing software on macos
229+
if: contains(matrix.os, 'macos')
230+
run: |
231+
# pcre was removed from runner images in November 2022
232+
brew install coreutils qt@6 pcre
233+
234+
- name: Run CMake on ubuntu (with GUI)
235+
if: contains(matrix.os, 'ubuntu')
236+
run: |
237+
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
238+
239+
- name: Run CMake on macos (with GUI)
240+
if: contains(matrix.os, 'macos')
241+
run: |
242+
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6
243+
244+
- name: Run CMake build
245+
run: |
246+
cmake --build cmake.output -- -j$(nproc)
247+
194248
build_uchar:
195249

196250
strategy:

.github/workflows/CI-windows.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ defaults:
1919
run:
2020
shell: cmd
2121

22-
# TODO: choose/add a step to bail out on compiler warnings (maybe even the release build)
23-
2422
jobs:
2523

2624
build_qt:
@@ -73,6 +71,33 @@ jobs:
7371
run: |
7472
cmake --build build --target install
7573
74+
build_cmake_cxxstd:
75+
strategy:
76+
matrix:
77+
os: [windows-2022, windows-2025]
78+
cxxstd: [14, 17]
79+
fail-fast: false
80+
81+
runs-on: ${{ matrix.os }}
82+
83+
steps:
84+
- uses: actions/checkout@v4
85+
with:
86+
persist-credentials: false
87+
88+
- name: Set up Visual Studio environment
89+
uses: ilammy/msvc-dev-cmd@v1
90+
with:
91+
arch: x64
92+
93+
- name: Run CMake
94+
run: |
95+
cmake -S . -B build.cxxstd -G "Visual Studio 17 2022" -A x64 -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel!
96+
97+
- name: Build
98+
run: |
99+
cmake --build build.cxxstd --config Debug || exit /b !errorlevel!
100+
76101
build:
77102
strategy:
78103
matrix:
@@ -142,8 +167,6 @@ jobs:
142167
python -m pip install pytest-xdist || exit /b !errorlevel!
143168
python -m pip install psutil || exit /b !errorlevel!
144169
145-
# TODO: build with CMake
146-
147170
- name: Build CLI debug configuration using MSBuild
148171
if: matrix.config == 'debug'
149172
run: |

cmake/cxx11.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
macro(use_cxx11)
2+
if(CMAKE_CXX_STANDARD EQUAL 98)
3+
message(FATAL_ERROR "C++ standard was set to ${CMAKE_CXX_STANDARD} but 11 is required as minimum")
4+
endif()
25
if(USE_BOOST AND USE_BOOST_INT128)
36
# Boost.Math requires C++14
7+
if(CMAKE_CXX_STANDARD LESS 14)
8+
message(FATAL_ERROR "C++ standard was set to ${CMAKE_CXX_STANDARD} but 14 is required as minimum")
9+
endif()
410
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to use")
511
else()
612
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")

democlient/democlient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CppcheckExecutor : public ErrorLogger {
6767
{}
6868

6969
void run(const char* code) {
70-
cppcheck.checkBuffer(FileWithDetails("test.cpp", Standards::Language::CPP, 0), reinterpret_cast<const uint8_t*>(code), strlen(code));
70+
cppcheck.checkBuffer(FileWithDetails("test.cpp", Standards::Language::CPP, 0), code, strlen(code));
7171
}
7272

7373
void reportOut(const std::string & /*outmsg*/, Color /*c*/) override {}

gui/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ void MainWindow::analyzeCode(const QString& code, const QString& filename)
736736
{
737737
const std::string code_s = code.toStdString();
738738
// TODO: apply enforcedLanguage?
739-
cppcheck.checkBuffer(FileWithDetails(filename.toStdString(), Path::identify(filename.toStdString(), false), 0), reinterpret_cast<const std::uint8_t*>(code_s.data()), code_s.size());
739+
cppcheck.checkBuffer(FileWithDetails(filename.toStdString(), Path::identify(filename.toStdString(), false), 0), code_s.data(), code_s.size());
740740
}
741741
analysisDone();
742742

lib/cppcheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ unsigned int CppCheck::check(const FileWithDetails &file)
799799
return returnValue;
800800
}
801801

802-
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const uint8_t* data, std::size_t size)
802+
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const char* data, std::size_t size)
803803
{
804804
return checkBuffer(file, "", 0, data, size);
805805
}
@@ -874,10 +874,10 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std:
874874
return preprocessor.calculateHash(toolinfo.str());
875875
}
876876

877-
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fileIndex, const uint8_t* data, std::size_t size)
877+
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fileIndex, const char* data, std::size_t size)
878878
{
879879
const auto f = [&file, data, size](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
880-
return simplecpp::TokenList{data, size, files, file.spath(), outputList};
880+
return simplecpp::TokenList{{data, size}, files, file.spath(), outputList};
881881
};
882882
return checkInternal(file, cfgname, fileIndex, f);
883883
}

lib/cppcheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class CPPCHECKLIB CppCheck {
108108
* @note You must set settings before calling this function (by calling
109109
* settings()).
110110
*/
111-
unsigned int checkBuffer(const FileWithDetails &file, const uint8_t* data, std::size_t size);
111+
unsigned int checkBuffer(const FileWithDetails &file, const char* data, std::size_t size);
112112

113113
/**
114114
* @brief Returns current version number as a string.
@@ -194,7 +194,7 @@ class CPPCHECKLIB CppCheck {
194194
* @param size the size of the data to be read
195195
* @return number of errors found
196196
*/
197-
unsigned int checkBuffer(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const uint8_t* data, std::size_t size);
197+
unsigned int checkBuffer(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const char* data, std::size_t size);
198198

199199
// TODO: should use simplecpp::OutputList
200200
using CreateTokenListFn = std::function<simplecpp::TokenList (std::vector<std::string>&, std::list<simplecpp::Output>*)>;

lib/tokenlist.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,17 @@ void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
321321

322322
//---------------------------------------------------------------------------
323323

324-
bool TokenList::createTokensFromBuffer(const uint8_t* data, size_t size)
324+
bool TokenList::createTokensFromBuffer(const char* data, size_t size)
325325
{
326326
return createTokensFromBufferInternal(data, size, mFiles.empty() ? "" : *mFiles.cbegin());
327327
}
328328

329329
//---------------------------------------------------------------------------
330330

331-
bool TokenList::createTokensFromBufferInternal(const uint8_t* data, size_t size, const std::string& file0)
331+
bool TokenList::createTokensFromBufferInternal(const char* data, size_t size, const std::string& file0)
332332
{
333333
simplecpp::OutputList outputList;
334-
simplecpp::TokenList tokens(data, size, mFiles, file0, &outputList);
334+
simplecpp::TokenList tokens({data, size}, mFiles, file0, &outputList);
335335

336336
createTokens(std::move(tokens));
337337

@@ -1866,7 +1866,12 @@ namespace {
18661866

18671867
~OnException() {
18681868
#ifndef _MSC_VER
1869-
if (std::uncaught_exception())
1869+
#if defined(__cpp_lib_uncaught_exceptions)
1870+
const bool b = std::uncaught_exceptions() > 0;
1871+
#else
1872+
const bool b = std::uncaught_exception();
1873+
#endif
1874+
if (b)
18701875
f();
18711876
#endif
18721877
}

lib/tokenlist.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ class CPPCHECKLIB TokenList {
9999
* - UTF in the code are not handled.
100100
* - comments are not handled.
101101
*/
102-
bool createTokensFromBuffer(const uint8_t* data, size_t size);
103-
bool createTokensFromBuffer(const char* data, size_t size) {
104-
return createTokensFromBuffer(reinterpret_cast<const uint8_t*>(data), size);
102+
bool createTokensFromBuffer(const uint8_t* data, size_t size) {
103+
return createTokensFromBuffer(reinterpret_cast<const char*>(data), size);
105104
}
105+
bool createTokensFromBuffer(const char* data, size_t size);
106106
template<size_t size>
107107
// cppcheck-suppress unusedFunction - used in tests only
108108
bool createTokensFromString(const char (&data)[size]) {
109-
return createTokensFromBuffer(reinterpret_cast<const uint8_t*>(data), size-1);
109+
return createTokensFromBuffer(data, size-1);
110110
}
111111

112112
void createTokens(simplecpp::TokenList&& tokenList);
@@ -216,7 +216,7 @@ class CPPCHECKLIB TokenList {
216216
}
217217

218218
private:
219-
bool createTokensFromBufferInternal(const uint8_t* data, std::size_t size, const std::string& file0);
219+
bool createTokensFromBufferInternal(const char* data, std::size_t size, const std::string& file0);
220220

221221
/** Token list */
222222
std::shared_ptr<TokensFrontBack> mTokensFrontBack;

oss-fuzz/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void doCheck(const uint8_t *data, size_t dataSize)
6464
{
6565
Suppressions supprs;
6666
CppCheck cppcheck(s_settings, supprs, s_errorLogger, false, nullptr);
67-
cppcheck.checkBuffer(s_file, data, dataSize);
67+
cppcheck.checkBuffer(s_file, reinterpret_cast<const char*>(data), dataSize);
6868
}
6969

7070
#ifndef NO_FUZZ

0 commit comments

Comments
 (0)