Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/cxx11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ macro(use_cxx11)
# Boost.Math requires C++14
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to use")
else()
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use")
endif()
endmacro()
4 changes: 4 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,11 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std:
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fileIndex, const uint8_t* data, std::size_t size)
{
const auto f = [&file, data, size](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
#if defined(__cpp_lib_string_view)
return simplecpp::TokenList{std::string_view{reinterpret_cast<const char*>(data), size}, files, file.spath(), outputList};
#else
return simplecpp::TokenList{data, size, files, file.spath(), outputList};
#endif
};
return checkInternal(file, cfgname, fileIndex, f);
}
Expand Down
11 changes: 10 additions & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ bool TokenList::createTokensFromBuffer(const uint8_t* data, size_t size)
bool TokenList::createTokensFromBufferInternal(const uint8_t* data, size_t size, const std::string& file0)
{
simplecpp::OutputList outputList;
#if defined(__cpp_lib_string_view)
simplecpp::TokenList tokens(std::string_view{reinterpret_cast<const char*>(data), size}, mFiles, file0, &outputList);
#else
simplecpp::TokenList tokens(data, size, mFiles, file0, &outputList);
#endif

createTokens(std::move(tokens));

Expand Down Expand Up @@ -1850,7 +1854,12 @@ namespace {

~OnException() {
#ifndef _MSC_VER
if (std::uncaught_exception())
#if defined(__cpp_lib_uncaught_exceptions)
const bool b = std::uncaught_exceptions() > 0;
#else
const bool b = std::uncaught_exception();
#endif
Comment on lines +1859 to +1861
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was deprecated in C++17.

if (b)
f();
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ ScopedFile::~ScopedFile() {

void SimpleTokenizer2::preprocess(const char* code, std::size_t size, std::vector<std::string> &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger)
{
#if defined(__cpp_lib_string_view)
simplecpp::TokenList tokens1(std::string_view{code, size}, files, file0);
#else
simplecpp::TokenList tokens1(code, size, files, file0);
#endif

Preprocessor preprocessor(tokens1, tokenizer.getSettings(), errorlogger, Path::identify(tokens1.getFiles()[0], false));
simplecpp::TokenList tokens2 = preprocessor.preprocess("", files, true);
Expand Down
10 changes: 6 additions & 4 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ class TestPreprocessor : public TestFixture {
simplecpp::OutputList outputList;
std::vector<std::string> files;

#if defined(__cpp_lib_string_view)
simplecpp::TokenList tokens(std::string_view{code, size}, files, Path::simplifyPath(filename), &outputList);
#else
simplecpp::TokenList tokens(code, size, files, Path::simplifyPath(filename), &outputList);
#endif
// TODO: we should be using the actual Preprocessor implementation
PreprocessorTest preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
if (inlineSuppression)
Expand Down Expand Up @@ -373,8 +377,7 @@ class TestPreprocessor : public TestFixture {
if (arg && std::strncmp(arg,"-U",2)==0)
settings.userUndefs.insert(arg+2);
std::vector<std::string> files;
// TODO: this adds an empty filename
simplecpp::TokenList tokens(code,files);
simplecpp::TokenList tokens(code,files,"test.c");
Preprocessor preprocessor(tokens, settings, *this, Standards::Language::C); // TODO: do we need to consider #file?
preprocessor.removeComments();
const std::set<std::string> configs = preprocessor.getConfigs();
Expand All @@ -387,8 +390,7 @@ class TestPreprocessor : public TestFixture {
template<size_t size>
std::size_t getHash(const char (&code)[size]) {
std::vector<std::string> files;
// TODO: this adds an empty filename
simplecpp::TokenList tokens(code,files);
simplecpp::TokenList tokens(code,files,"test.c");
Preprocessor preprocessor(tokens, settingsDefault, *this, Standards::Language::C); // TODO: do we need to consider #file?
preprocessor.removeComments();
return preprocessor.calculateHash("");
Expand Down