Skip to content

[libc] Make test macros suppress the -Wdangling-else warnings #127149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
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
9 changes: 9 additions & 0 deletions libc/test/UnitTest/LibcTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ CString libc_make_test_file_path_func(const char *file_name);
SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \
void SuiteClass##_##TestName::Run()

// Helper to trick the compiler into ignoring lack of braces on the else
// branch. We cannot introduce braces at this point, since it would prevent
// using `<< ...` after the test macro for additional failure output.
#define LIBC_TEST_DISABLE_DANGLING_ELSE \
switch (0) \
case 0: \
default: // NOLINT

// If RET_OR_EMPTY is the 'return' keyword we perform an early return which
// corresponds to an assert. If it is empty the execution continues, this
// corresponds to an expect.
Expand All @@ -411,6 +419,7 @@ CString libc_make_test_file_path_func(const char *file_name);
// returning a boolean. This expression is responsible for logging the
// diagnostic in case of failure.
#define LIBC_TEST_SCAFFOLDING_(TEST, RET_OR_EMPTY) \
LIBC_TEST_DISABLE_DANGLING_ELSE \
if (TEST) \
; \
else \
Expand Down
Loading