Skip to content
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: 7 additions & 2 deletions include/etl/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,13 @@ SOFTWARE.
#define ETL_ENUM_CLASS(name) enum class name
#define ETL_ENUM_CLASS_TYPE(name, type) enum class name : type
#define ETL_LVALUE_REF_QUALIFIER &
#define ETL_NOEXCEPT noexcept
#define ETL_NOEXCEPT_EXPR(...) noexcept(__VA_ARGS__)
#if ETL_USING_EXCEPTIONS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jwellbelove, if you don't like using this flag, I can also recommend using the feature test macro in the C++ standard:

#if defined(__cpp_exceptions)

#define ETL_NOEXCEPT noexcept
#define ETL_NOEXCEPT_EXPR(...) noexcept(__VA_ARGS__)
#else
#define ETL_NOEXCEPT
#define ETL_NOEXCEPT_EXPR(...)
#endif
Comment on lines +334 to +340
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Conditional noexcept correctly implements IAR workaround.

The conditional definition properly addresses IAR 8.x's rejection of the noexcept keyword when exceptions are disabled. The logic is sound: when ETL_USING_EXCEPTIONS is true, the macros expand to standard noexcept specifications; when false, they expand to empty, avoiding the IAR build error.

Verify that this change doesn't adversely affect other supported compilers. Run the following script to check for any direct usage of noexcept (not via macros) in the codebase:


🏁 Script executed:

#!/bin/bash
# Description: Find any direct usage of noexcept keyword that might need similar treatment

# Search for noexcept keyword usage outside of macro definitions
rg -n --type=cpp --type=c -g '!platform.h' '\bnoexcept\b' -C2

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Search for direct usages of noexcept outside the macro definitions,
# excluding include/etl/platform.h
rg -n --type=c --type=cpp '\bnoexcept\b' -C2 --glob '!include/etl/platform.h'

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Search for direct usages of noexcept outside platform.h without type filters
rg -n 'noexcept\b' -C2 --glob '!include/etl/platform.h'

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Broad search for any direct usage of noexcept in the codebase
rg -n 'noexcept\b' -C2

Length of output: 41748


Use ETL_NOEXCEPT instead of raw noexcept
Direct noexcept occurrences (e.g. in test files and include/etl/data.h) bypass the new conditional and may still break IAR when exceptions are disabled. Replace them with ETL_NOEXCEPT or ETL_NOEXCEPT_EXPR as appropriate.

🤖 Prompt for AI Agents
In include/etl/platform.h around lines 334 to 340, raw uses of the C++ keyword
noexcept are still present elsewhere (e.g. test files and include/etl/data.h)
and will bypass the ETL conditional macros when exceptions are disabled; search
for all direct occurrences of "noexcept" and replace them with ETL_NOEXCEPT, and
replace instances that use noexcept(...) with ETL_NOEXCEPT_EXPR(...), making
sure the file includes include/etl/platform.h (or otherwise has those macros
visible) so builds targeting IAR with ETL_USING_EXCEPTIONS disabled use the
conditional definitions.

#else
#define ETL_CONSTEXPR
#define ETL_CONSTEXPR11
Expand Down
Loading