Skip to content

use libc++ in conjunction with Clang in CI#6820

Draft
firewave wants to merge 6 commits intodanmar:mainfrom
firewave:libcxx-ci
Draft

use libc++ in conjunction with Clang in CI#6820
firewave wants to merge 6 commits intodanmar:mainfrom
firewave:libcxx-ci

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

It provides additional annotations for the compiler and the sanitizers to detect more issues.

@firewave firewave force-pushed the libcxx-ci branch 2 times, most recently from 98c59ce to d1247cd Compare September 22, 2024 17:35
@firewave
Copy link
Copy Markdown
Collaborator Author

firewave commented Sep 22, 2024

[238/238][20.0s] clang-tidy-19 -p=/home/runner/work/cppcheck/cppcheck/cmake.output -quiet /home/runner/work/cppcheck/cppcheck/gui/xmlreport.cpp
/home/runner/work/cppcheck/cppcheck/lib/utils.h:57:5: error: an exception may be thrown in function '~OnExit' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
   57 |     ~OnExit() {
      |     ^

I filed a ticket about the OnExit bugprone-exception-escape false positive(?) upstream: llvm/llvm-project#109587.

@firewave

This comment was marked as resolved.

@firewave

This comment was marked as resolved.

@firewave

This comment was marked as resolved.

return Token::Match(child, "&&|%oror%");
}))
return false;
// NOLINTNEXTLINE(bugprone-nondeterministic-pointer-iteration-order) - FP with libc++ only
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 4, 2025

struct OnExit {
std::function<void()> f;

// NOLINTNEXTLINE(bugprone-exception-escape) - reported with libc++ for any files which includes this (even if not used)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/utils.h:57:5: error: an exception may be thrown in function '~OnExit' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
   57 |     ~OnExit() {
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/__functional/function.h:74:3: note: frame #0: unhandled exception of type 'std::bad_function_call' may be thrown in function '__throw_bad_function_call' here
   74 |   throw bad_function_call();
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/__functional/function.h:273:7: note: frame #1: function 'operator()' calls function '__throw_bad_function_call' here
  273 |       std::__throw_bad_function_call();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/__functional/function.h:772:10: note: frame #2: function 'operator()' calls function 'operator()' here
  772 |   return __f_(std::forward<_ArgTypes>(__arg)...);
      |          ^
/home/runner/work/cppcheck/cppcheck/lib/utils.h:58:10: note: frame #3: function '~OnExit' calls function 'operator()' here
   58 |         f();
      |          ^

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reported upstream as llvm/llvm-project#109587.

struct OnException {
std::function<void()> f;

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/tokenlist.cpp:1844:9: error: an exception may be thrown in function '~OnException' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
 1844 |         ~OnException() {
      |         ^
/usr/lib/llvm-21/bin/../include/c++/v1/__functional/function.h:74:3: note: frame #0: unhandled exception of type 'std::bad_function_call' may be thrown in function '__throw_bad_function_call' here
   74 |   throw bad_function_call();
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/__functional/function.h:273:7: note: frame #1: function 'operator()' calls function '__throw_bad_function_call' here
  273 |       std::__throw_bad_function_call();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/__functional/function.h:772:10: note: frame #2: function 'operator()' calls function 'operator()' here
  772 |   return __f_(std::forward<_ArgTypes>(__arg)...);
      |          ^
/home/runner/work/cppcheck/cppcheck/lib/tokenlist.cpp:1847:18: note: frame #3: function '~OnException' calls function 'operator()' here
 1847 |                 f();
      |                  ^

const Token * const mToken;
};

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/templatesimplifier.cpp:77:11: error: an exception may be thrown in function 'FindName' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
   77 |     class FindName {
      |           ^
/usr/lib/llvm-21/bin/../include/c++/v1/stdexcept:243:3: note: frame #0: unhandled exception of type 'std::length_error' may be thrown in function '__throw_length_error' here
  243 |   throw length_error(__msg);
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2463:5: note: frame #1: function '__throw_length_error' calls function '__throw_length_error' here
 2463 |     std::__throw_length_error("basic_string");
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2569:7: note: frame #2: function '__init_copy_ctor_external' calls function '__throw_length_error' here
 2569 |       this->__throw_length_error();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:997:7: note: frame #3: function 'basic_string' calls function '__init_copy_ctor_external' here
  997 |       __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
      |       ^
/home/runner/work/cppcheck/cppcheck/lib/templatesimplifier.cpp:77:11: note: frame #4: function 'FindName' calls function 'basic_string' here
   77 |     class FindName {
      |           ^

const std::string mName;
};

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/templatesimplifier.cpp:87:11: error: an exception may be thrown in function 'FindFullName' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
   87 |     class FindFullName {
      |           ^
/usr/lib/llvm-21/bin/../include/c++/v1/stdexcept:243:3: note: frame #0: unhandled exception of type 'std::length_error' may be thrown in function '__throw_length_error' here
  243 |   throw length_error(__msg);
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2463:5: note: frame #1: function '__throw_length_error' calls function '__throw_length_error' here
 2463 |     std::__throw_length_error("basic_string");
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2569:7: note: frame #2: function '__init_copy_ctor_external' calls function '__throw_length_error' here
 2569 |       this->__throw_length_error();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:997:7: note: frame #3: function 'basic_string' calls function '__init_copy_ctor_external' here
  997 |       __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
      |       ^
/home/runner/work/cppcheck/cppcheck/lib/templatesimplifier.cpp:87:11: note: frame #4: function 'FindFullName' calls function 'basic_string' here
   87 |     class FindFullName {
      |           ^


ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::string& filename, const std::vector<std::string>& fileFilters, std::vector<SharedItemsProject> &cache)
{
// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/importproject.cpp:912:27: error: an exception may be thrown in function '(lambda at /home/runner/work/cppcheck/cppcheck/lib/importproject.cpp:912:27)' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
  912 |     auto isInCacheCheck = [filename](const ImportProject::SharedItemsProject& e) -> bool {
      |                           ^
/usr/lib/llvm-21/bin/../include/c++/v1/stdexcept:243:3: note: frame #0: unhandled exception of type 'std::length_error' may be thrown in function '__throw_length_error' here
  243 |   throw length_error(__msg);
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2463:5: note: frame #1: function '__throw_length_error' calls function '__throw_length_error' here
 2463 |     std::__throw_length_error("basic_string");
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2569:7: note: frame #2: function '__init_copy_ctor_external' calls function '__throw_length_error' here
 2569 |       this->__throw_length_error();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:997:7: note: frame #3: function 'basic_string' calls function '__init_copy_ctor_external' here
  997 |       __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
      |       ^
/home/runner/work/cppcheck/cppcheck/lib/importproject.cpp:912:27: note: frame #4: function '(lambda at /home/runner/work/cppcheck/cppcheck/lib/importproject.cpp:912:27)' calls function 'basic_string' here
  912 |     auto isInCacheCheck = [filename](const ImportProject::SharedItemsProject& e) -> bool {
      |                           ^

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is fixed by passing it by reference instead of copying it.

gui/main.cpp Outdated
static void ShowVersion();
static bool CheckArgs(const QStringList &args);

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/gui/main.cpp:48:5: error: an exception may be thrown in function 'main' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
   48 | int main(int argc, char *argv[])
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/__new/exceptions.h:66:3: note: frame #0: unhandled exception of type 'std::bad_array_new_length' may be thrown in function '__throw_bad_array_new_length' here
   66 |   throw bad_array_new_length();
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/__memory/allocator.h:101:7: note: frame #1: function 'allocate' calls function '__throw_bad_array_new_length' here
  101 |       std::__throw_bad_array_new_length();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/__memory/allocate_at_least.h:41:11: note: frame #2: function '__allocate_at_least<std::allocator<char>>' calls function 'allocate' here
   41 |   return {__alloc.allocate(__n), __n};
      |           ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2545:25: note: frame #3: function '__init' calls function '__allocate_at_least<std::allocator<char>>' here
 2545 |     auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__sz) + 1);
      |                         ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:1053:5: note: frame #4: function 'basic_string<0>' calls function '__init' here
 1053 |     __init(__s, traits_type::length(__s));
      |     ^
/home/runner/work/cppcheck/cppcheck/gui/main.cpp:132:17: note: frame #5: function 'ShowVersion' calls function 'basic_string<0>' here
  132 |     std::string versionMessage("Cppcheck ");
      |                 ^
/home/runner/work/cppcheck/cppcheck/gui/main.cpp:92:9: note: frame #6: function 'CheckArgs' calls function 'ShowVersion' here
   92 |         ShowVersion();
      |         ^
/home/runner/work/cppcheck/cppcheck/gui/main.cpp:70:10: note: frame #7: function 'main' calls function 'CheckArgs' here
   70 |     if (!CheckArgs(QApplication::arguments()))
      |          ^

lib/ctu.h Outdated
bool loadBaseFromXml(const tinyxml2::XMLElement *xmlElement);
};

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/ctu.h:112:15: error: an exception may be thrown in function 'FunctionCall' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
  112 |         class FunctionCall : public CallBase {
      |               ^
/usr/lib/llvm-21/bin/../include/c++/v1/stdexcept:243:3: note: frame #0: unhandled exception of type 'std::length_error' may be thrown in function '__throw_length_error' here
  243 |   throw length_error(__msg);
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2463:5: note: frame #1: function '__throw_length_error' calls function '__throw_length_error' here
 2463 |     std::__throw_length_error("basic_string");
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2569:7: note: frame #2: function '__init_copy_ctor_external' calls function '__throw_length_error' here
 2569 |       this->__throw_length_error();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:997:7: note: frame #3: function 'basic_string' calls function '__init_copy_ctor_external' here
  997 |       __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
      |       ^
/home/runner/work/cppcheck/cppcheck/lib/ctu.h:102:13: note: frame #4: function 'CallBase' calls function 'basic_string' here
  102 |             CallBase(const CallBase&) = default;
      |             ^
/home/runner/work/cppcheck/cppcheck/lib/ctu.h:112:15: note: frame #5: function 'FunctionCall' calls function 'CallBase' here
  112 |         class FunctionCall : public CallBase {
      |               ^

lib/ctu.h Outdated
bool loadFromXml(const tinyxml2::XMLElement *xmlElement);
};

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/lib/ctu.h:124:15: error: an exception may be thrown in function 'NestedCall' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
  124 |         class NestedCall : public CallBase {
      |               ^
/usr/lib/llvm-21/bin/../include/c++/v1/stdexcept:243:3: note: frame #0: unhandled exception of type 'std::length_error' may be thrown in function '__throw_length_error' here
  243 |   throw length_error(__msg);
      |   ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2463:5: note: frame #1: function '__throw_length_error' calls function '__throw_length_error' here
 2463 |     std::__throw_length_error("basic_string");
      |     ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:2569:7: note: frame #2: function '__init_copy_ctor_external' calls function '__throw_length_error' here
 2569 |       this->__throw_length_error();
      |       ^
/usr/lib/llvm-21/bin/../include/c++/v1/string:997:7: note: frame #3: function 'basic_string' calls function '__init_copy_ctor_external' here
  997 |       __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
      |       ^
/home/runner/work/cppcheck/cppcheck/lib/ctu.h:102:13: note: frame #4: function 'CallBase' calls function 'basic_string' here
  102 |             CallBase(const CallBase&) = default;
      |             ^
/home/runner/work/cppcheck/cppcheck/lib/ctu.h:124:15: note: frame #5: function 'NestedCall' calls function 'CallBase' here
  124 |         class NestedCall : public CallBase {
      |               ^

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reported upstream as llvm/llvm-project#152026.

This also lacks the actual source location which is triggering it. I was not able to get a minimized example for that yet.

fout << "\t$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -DNO_FUZZ -c -o $@ main.cpp\n";
}

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/home/runner/work/cppcheck/cppcheck/tools/dmake/dmake.cpp:417:5: error: an exception may be thrown in function 'main' which should not throw exceptions [bugprone-exception-escape,-warnings-as-errors]
  417 | int main(int argc, char **argv)
      |     ^
/usr/bin/../include/c++/v1/stdexcept:251:3: note: frame #0: unhandled exception of type 'std::out_of_range' may be thrown in function '__throw_out_of_range' here
  251 |   throw out_of_range(__msg);
      |   ^
/usr/bin/../include/c++/v1/string:2467:5: note: frame #1: function '__throw_out_of_range' calls function '__throw_out_of_range' here
 2467 |     std::__throw_out_of_range("basic_string");
      |     ^
/usr/bin/../include/c++/v1/string:3528:5: note: frame #2: function 'compare' calls function '__throw_out_of_range' here
 3528 |     this->__throw_out_of_range();
      |     ^
/usr/bin/../include/c++/v1/string:2025:12: note: frame #3: function 'compare' calls function 'compare' here
 2025 |     return compare(__pos1, __n1, __s, traits_type::length(__s));
      |            ^
/home/runner/work/cppcheck/cppcheck/cli/../lib/utils.h:97:12: note: frame #4: function 'startsWith' calls function 'compare' here
   97 |     return str.compare(0, startlen, start) == 0;
      |            ^
/home/runner/work/cppcheck/cppcheck/cli/../lib/utils.h:103:12: note: frame #5: function 'startsWith<11UL>' calls function 'startsWith' here
  103 |     return startsWith(str, start, N - 1);
      |            ^
/home/runner/work/cppcheck/cppcheck/tools/dmake/dmake.cpp:151:29: note: frame #6: function 'compilefiles' calls function 'startsWith<11UL>' here
  151 |         const bool external(startsWith(file,"externals/") || startsWith(file,"../externals/"));
      |                             ^
/home/runner/work/cppcheck/cppcheck/tools/dmake/dmake.cpp:873:5: note: frame #7: function 'main' calls function 'compilefiles' here
  873 |     compilefiles(fout, libfiles_prio, "${INCLUDE_FOR_LIB}");
      |     ^

@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

Comment on lines -741 to +742
const std::string::size_type paren = define.find("(");
const std::string::size_type space = define.find(" ");
const std::string::size_type paren = define.find('(');
const std::string::size_type space = define.find(' ');
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I filed llvm/llvm-project#182012 about these only being found with libc++.

@firewave firewave force-pushed the libcxx-ci branch 2 times, most recently from 31706c2 to 859e271 Compare February 18, 2026 13:27
@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant