Skip to content

Conversation

christophruethingbmw
Copy link

Currently, in case we use a parameter of a function only inside of an ETL_ASSERT and the ETL configuration disables the ETL_ASSERT, we get a compiler warning about an unused parameter. Therefore, this change casts the condition of ETL_ASSERT to void.

John Wellbelove and others added 6 commits September 12, 2025 20:19
Removed ETL_NOEXCEPT from closureoperator(), call_if(), and call_or()
In addition to removing noexcept from call_if, this is also needed to prevent
an abort when cancelling a pthread that is executing a delegate.
Currently, in case we use a parameter of a function _only_ inside of an
ETL_ASSERT and the ETL configuration disables the ETL_ASSERT, we get a
compiler warning about an unused parameter. Therefore, this change casts
the condition of ETL_ASSERT to void.
Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

Macros in include/etl/error_handler.h were modified so that under ETL_NO_CHECKS many assert macros (ETL_ASSERT, ETL_ASSERT_OR_RETURN, ETL_ASSERT_OR_RETURN_VALUE and ETL_ASSERT_FAIL variants) now evaluate to static_cast<void>(sizeof(b)) instead of a no-op. The non-assert-function path for ETL_ASSERT was aligned similarly. Behaviour for enabled checks is unchanged. Some ETL_ASSERT_FAIL variants reference b inside their no-check expansion where b is not defined, which may cause compilation errors. No public API declarations were changed.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title succinctly reflects the main change by indicating the introduction of a cast to void for assert conditions, which aligns with the implementation of casting ETL_ASSERT expressions to void to suppress unused‐parameter warnings.
Description Check ✅ Passed The pull request description directly addresses the unused‐parameter warning caused by disabled asserts and explains that casting the assert condition to void resolves this issue, which aligns with the described changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0ac3b8 and 66a01db.

📒 Files selected for processing (1)
  • include/etl/error_handler.h (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
include/etl/*.h

⚙️ CodeRabbit configuration file

include/etl/*.h: Review the C++ code in these directories. The code must not use
STL containers but must instead rely on Embedded Template Library
(ETL) for data structures and algorithms.

When answering questions, provide accurate and concise information based on the ETL documentation and codebase. If you don't know the answer, just say "I don't know". Do not make up answers.
When providing code examples, ensure they are relevant to the ETL and follow its conventions.
Always be polite and professional in your responses.

Header files should start with the ETL's standard MIT comment block.

Header files should have include guards in the format '#ifndef ETL_>INCLUDED #define ETL_INCLUDED #endif'

Headers should be organized in the following order

  • The first header include should be '#include "platform.h"'
  • Headers from the ETL
  • Headers from the path 'private/**'
  • C++ standard library headers
  • C standard library headers

Pay extra attention to the following

  • Buffer overflows
  • Memory leaks
  • Undefined behavior

Check that the following conventions are used

  • Variable names should be in snake_case
  • Macro constants should be ALL_CAPS_WITH_UNDERSCORES
  • Macro constants should be prefixed with 'ETL_'
  • Function, class, and type names should be snake_case
  • enum members should be Caps_Snake_Case

Please keep your outputs short and to the point, unless otherwise asked

  • Keep your responses short, describe small issues in a few sentences
  • Don't output tips, analysis chains or anything else with a collapsible view
  • Don't output comment summaries or fix prompts for AIs
  • If the highlighted issue is complex, don't suggest a solution
  • Don't use emojis

Files:

  • include/etl/error_handler.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: Clang C++11 Linux - No STL (ubuntu-22.04)
  • GitHub Check: Clang C++11 Linux - STL (ubuntu-22.04)
  • GitHub Check: GCC C++14 Linux - STL (ubuntu-22.04)
  • GitHub Check: Clang C++17 Linux - STL (ubuntu-22.04)
  • GitHub Check: GCC C++14 Linux - No STL (ubuntu-22.04)
  • GitHub Check: Clang C++17 Linux - No STL (ubuntu-22.04)
  • GitHub Check: Windows - No STL
  • GitHub Check: GCC C++20 Linux - No STL (ubuntu-22.04)
  • GitHub Check: Clang C++23 OSX - STL (macos-13)
  • GitHub Check: Clang C++14 Linux - No STL (ubuntu-22.04)
  • GitHub Check: GCC C++23 Linux - STL - Force C++03 (ubuntu-22.04)
  • GitHub Check: Clang C++23 OSX - No STL (macos-13)
  • GitHub Check: Clang C++20 Linux - No STL (ubuntu-22.04)
  • GitHub Check: Clang C++23 Linux - No STL - Force C++03 (ubuntu-22.04)
  • GitHub Check: Clang C++20 Linux - STL - Force C++03 (ubuntu-22.04)
  • GitHub Check: Clang C++20 OSX - STL (macos-13)
  • GitHub Check: Clang C++23 Linux - STL - Force C++03 (ubuntu-22.04)
  • GitHub Check: Clang C++14 Linux - STL (ubuntu-22.04)
  • GitHub Check: Clang C++23 Linux - No STL (ubuntu-22.04)
  • GitHub Check: GCC C++23 Linux - No STL (ubuntu-22.04)
🔇 Additional comments (2)
include/etl/error_handler.h (2)

304-306: Implementation aligns with agreed approach.

The use of static_cast<void>(sizeof(b)) correctly prevents evaluation of b whilst silencing unused-parameter warnings, as agreed in the PR discussion.


356-356: Implementation aligns with agreed approach.

The use of static_cast<void>(sizeof(b)) correctly prevents evaluation of b whilst silencing unused-parameter warnings in release builds, consistent with the ETL_NO_CHECKS branch.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9cf20d and a0ac3b8.

📒 Files selected for processing (1)
  • include/etl/error_handler.h (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
include/etl/*.h

⚙️ CodeRabbit configuration file

include/etl/*.h: Review the C++ code in these directories. The code must not use
STL containers but must instead rely on Embedded Template Library
(ETL) for data structures and algorithms.

When answering questions, provide accurate and concise information based on the ETL documentation and codebase. If you don't know the answer, just say "I don't know". Do not make up answers.
When providing code examples, ensure they are relevant to the ETL and follow its conventions.
Always be polite and professional in your responses.

Header files should start with the ETL's standard MIT comment block.

Header files should have include guards in the format '#ifndef ETL_>INCLUDED #define ETL_INCLUDED #endif'

Headers should be organized in the following order

  • The first header include should be '#include "platform.h"'
  • Headers from the ETL
  • Headers from the path 'private/**'
  • C++ standard library headers
  • C standard library headers

Pay extra attention to the following

  • Buffer overflows
  • Memory leaks
  • Undefined behavior

Check that the following conventions are used

  • Variable names should be in snake_case
  • Macro constants should be ALL_CAPS_WITH_UNDERSCORES
  • Macro constants should be prefixed with 'ETL_'
  • Function, class, and type names should be snake_case
  • enum members should be Caps_Snake_Case

Please keep your outputs short and to the point, unless otherwise asked

  • Keep your responses short, describe small issues in a few sentences
  • Don't output tips, analysis chains or anything else with a collapsible view
  • Don't output comment summaries or fix prompts for AIs
  • If the highlighted issue is complex, don't suggest a solution
  • Don't use emojis

Files:

  • include/etl/error_handler.h
🧠 Learnings (2)
📓 Common learnings
Learnt from: filipe-cuim
PR: ETLCPP/etl#1174
File: include/etl/type_traits.h:1974-1985
Timestamp: 2025-09-01T14:17:35.361Z
Learning: The current implementation in this PR correctly uses only individual trait flags (like ETL_USING_BUILTIN_IS_ASSIGNABLE) in preprocessor guards, not the global ETL_USE_TYPE_TRAITS_BUILTINS flag, because the global flag automatically defines all individual flags when enabled, making dual checks redundant.
📚 Learning: 2025-09-01T14:17:35.361Z
Learnt from: filipe-cuim
PR: ETLCPP/etl#1174
File: include/etl/type_traits.h:1974-1985
Timestamp: 2025-09-01T14:17:35.361Z
Learning: The current implementation in this PR correctly uses only individual trait flags (like ETL_USING_BUILTIN_IS_ASSIGNABLE) in preprocessor guards, not the global ETL_USE_TYPE_TRAITS_BUILTINS flag, because the global flag automatically defines all individual flags when enabled, making dual checks redundant.

Applied to files:

  • include/etl/error_handler.h

Comment on lines 308 to 311
#define ETL_ASSERT_FAIL(e) static_cast<void>(b) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN(e) static_cast<void>(b) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) static_cast<void>(b) // Does nothing.
#elif defined(ETL_USE_ASSERT_FUNCTION)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

ETL_ASSERT_FAIL macros reference undefined identifier ‘b’

These expand to static_cast(b) but ‘b’ is not a macro parameter here, causing a compile error. They should be true no‑ops and must not evaluate ‘e’.

Apply this diff to align with the existing release branch behaviour (lines 360–363):

-  #define ETL_ASSERT_FAIL(e) static_cast<void>(b)                     // Does nothing.
-  #define ETL_ASSERT_FAIL_AND_RETURN(e) static_cast<void>(b)          // Does nothing.
-  #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) static_cast<void>(b) // Does nothing.
+  #define ETL_ASSERT_FAIL(e)                                          // Does nothing.
+  #define ETL_ASSERT_FAIL_AND_RETURN(e) {return;}                     // Returns.
+  #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {return (v);}        // Returns a value.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#define ETL_ASSERT_FAIL(e) static_cast<void>(b) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN(e) static_cast<void>(b) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) static_cast<void>(b) // Does nothing.
#elif defined(ETL_USE_ASSERT_FUNCTION)
#define ETL_ASSERT_FAIL(e) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN(e) {return;} // Returns.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {return (v);} // Returns a value.
#elif defined(ETL_USE_ASSERT_FUNCTION)
🤖 Prompt for AI Agents
In include/etl/error_handler.h around lines 308 to 311, the ETL_ASSERT_FAIL
macros incorrectly reference an undefined identifier 'b' (static_cast<void>(b))
which causes a compile error; update each macro so it is a true no‑op that does
not evaluate 'e' (match the release branch behavior) by replacing the
static_cast(void)(b) with a safe no‑op such as static_cast<void>(0) (or (void)0)
for ETL_ASSERT_FAIL, ETL_ASSERT_FAIL_AND_RETURN and
ETL_ASSERT_FAIL_AND_RETURN_VALUE.

@jwellbelove
Copy link
Contributor

ChatGPT points out that using (void)sizeof(b); would get around the issue of b being evaluated.

@christophruethingbmw
Copy link
Author

christophruethingbmw commented Sep 29, 2025

Hi @jwellbelove, I am unsure what is the intended behavior, I agree that using sizeof(b) would never evaluate b. My two cents:

  • In case somebody adds an expression with side-effects into an ETL_ASSERT, we might even want that it is not eliminated? I think this is not intended usage of this, i.e. the expression inside of ETL_ASSERT should neve have side effects, but you never now. Like it is done here, we have a t least a consistent behavior for all ETL profile settings.
  • I would argue that any decent compiler will optimize away the evaluation of the expression in case it has no side-effects. I think that's the case for most of the usages.

I have no strong preference here, what do you think?

@jwellbelove
Copy link
Contributor

The standard assert will not evaluate arguments when not in a debug build, so I think that stating the same for ETL_ASSERT would be valid.

@christophruethingbmw
Copy link
Author

christophruethingbmw commented Sep 29, 2025

@jwellbelove , okay, I changed it to static_cast<void>(sizeof(b)). Can you please have a look?

In case we disable ASSERTs in e.g. non debug builds, we want to expand
it to "nothing", similar to how the std assert works. Introducing a cast
to void on the conidition would still evaluate it and potentially cause
side-effects. Therefore, we use the sizeof operator to ensure the
expression is not evaluated in case ASSERTs are disabled.
@jwellbelove jwellbelove changed the base branch from master to pull-request/#1191-Introduce-Cast-to-void-for-Condition-of-Assert October 1, 2025 17:16
@jwellbelove jwellbelove merged commit 018c7ce into ETLCPP:pull-request/#1191-Introduce-Cast-to-void-for-Condition-of-Assert Oct 1, 2025
83 checks passed
jwellbelove pushed a commit that referenced this pull request Oct 2, 2025
…-of-Assert' into development

# Conflicts:
#	include/etl/error_handler.h
jwellbelove added a commit that referenced this pull request Oct 11, 2025
* Removed ETL_NOEXCEPT from delegate operator(), call_if(), and call_or()

Removed ETL_NOEXCEPT from closureoperator(), call_if(), and call_or()

* Updated version and release notes

* Updated version and release notes

* Remove noexcept from delegate method stubs. (#1185)

In addition to removing noexcept from call_if, this is also needed to prevent
an abort when cancelling a pthread that is executing a delegate.

* Updated version and release notes

* Introduce Cast to void for Condition of Assert

Currently, in case we use a parameter of a function _only_ inside of an
ETL_ASSERT and the ETL configuration disables the ETL_ASSERT, we get a
compiler warning about an unused parameter. Therefore, this change casts
the condition of ETL_ASSERT to void.

* Use sizeof to avoid evaluation of Expression

In case we disable ASSERTs in e.g. non debug builds, we want to expand
it to "nothing", similar to how the std assert works. Introducing a cast
to void on the conidition would still evaluate it and potentially cause
side-effects. Therefore, we use the sizeof operator to ensure the
expression is not evaluated in case ASSERTs are disabled.

---------

Co-authored-by: John Wellbelove <[email protected]>
Co-authored-by: Marco Nilsson <[email protected]>
Co-authored-by: John Wellbelove <[email protected]>
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.

4 participants