Skip to content
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

add static assert with auto message #740

Conversation

dhebbeker
Copy link
Contributor

@dhebbeker dhebbeker commented Aug 10, 2023

Suggested changes:

  • Add overload to function-like macro ETL_STATIC_ASSERT() for only one argument (condition). That overload does either call static_assert() if C++17 is used or calls ETL_STATIC_ASSERT() where the second (message) argument is generated by stringifying the condition.
  • In order to perform overload resolution with function-like macros a helper macro has been added to resolve overloads of 1 or 2 arguments.

⚠ Warning: The overload resolution mechanism does use variadic macros (__VA_ARGS__). These were officially added in C99 and C++11. When compiling with -std=c++98 modern compilers issue a warning (see example). I also tested it with IAR C/C++ Compiler for AVR 6.70.1 which officially only supports C++98 (Extended Embedded C++), without warnings or errors.

In case these changes are accepted, the documentation on the website must be updated.

@semanticdiff-com
Copy link

View changes with SemanticDiff

@jwellbelove jwellbelove changed the base branch from master to feature/add-static_assert-with-auto-message August 10, 2023 11:13
@jwellbelove jwellbelove deleted the branch ETLCPP:pull-request/#740-add-static-assert-with-auto-message August 11, 2023 08:32
@jwellbelove jwellbelove reopened this Aug 11, 2023
@jwellbelove jwellbelove changed the base branch from feature/add-static_assert-with-auto-message to pull-request/#740-add-static-assert-with-auto-message August 11, 2023 09:06
dhebbeker and others added 18 commits August 11, 2023 10:09
* Add include/linux/stringify.h from Linux kernel 2.6.12-rc2

(cherry picked from commit torvalds/linux@1da177e)

* Make __stringify support variable argument macros too

For example:

  __stringify(__entry->irq, __entry->ret)

will now convert it to:

  "REC->irq, REC->ret"

It also still supports single arguments as the old macro did.

Signed-off-by: Zhao Lei <[email protected]>
Acked-by: Frederic Weisbecker <[email protected]>
Cc: Steven Rostedt <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
(cherry picked from commit torvalds/linux@8f7c2c3)

* Add documentation.

* Adjust names in order to satisfy naming convention.

* Use __VA_ARGS__ instead a GNU extension as this works with more compilers.

Works with the newest versions of ICCAVR, GCC, CLANG and MSCV. C++11 may be required.

* Adjust to ETL folder structure.

* Change include guard to the one usual in ETL.

* Add definition guard for STRINGIFY.

---------

Co-authored-by: Linus Torvalds <[email protected]>
Co-authored-by: Zhaolei <[email protected]>
Warning[Pe111]: statement is unreachable
Minor format edit
@dhebbeker dhebbeker marked this pull request as draft November 9, 2023 09:58
@dhebbeker dhebbeker force-pushed the feature/add-static_assert-with-auto-message branch from 4d6e7a6 to ff48106 Compare November 9, 2023 10:01
@dhebbeker dhebbeker marked this pull request as ready for review November 9, 2023 10:03
@dhebbeker dhebbeker marked this pull request as draft November 9, 2023 10:09
@dhebbeker dhebbeker force-pushed the feature/add-static_assert-with-auto-message branch from 0b1762b to 9f5528c Compare November 9, 2023 10:12
John Wellbelove and others added 2 commits November 9, 2023 11:49
(cherry picked from commit f208eb4)

The line got lost in 95c7f44.
… 2 arguments.

Inspired by https://stackoverflow.com/a/11763277/

Warning: This requires support for variadic macros (`__VA_ARGS__`). These were officially added in C99 and C++11.
@dhebbeker dhebbeker force-pushed the feature/add-static_assert-with-auto-message branch from 9f5528c to 7771cf3 Compare November 9, 2023 11:11
(cherry picked from commit 91e7f46)
@dhebbeker
Copy link
Contributor Author

I rebased this branch in order to make use of the extended workflow settings (3173d7e).

@dhebbeker
Copy link
Contributor Author

dhebbeker commented Nov 9, 2023

This branch is currently based on 4eb46d6 of branch dhebbeker:feature/try-to-fix-GitHub-Actions-for-clang-C++20 (#784). Those unrelated changes should not be part of this pull request. But they simplify to check the changes of this pull request as they fix unrelated failures in the workflow (GitHub Actions).

  • unrelated changes must be removed from source branch

The unrelated changes will be removed from this pull request as soon as they will be merged into the target/base branch of this pull request. Alternatively the source branch of this pull request may be rebased onto its merge-base to the target/base branch while omitting the unrelated changes.

@jwellbelove jwellbelove marked this pull request as ready for review December 4, 2023 14:44
@jwellbelove jwellbelove merged commit 3392a6c into ETLCPP:pull-request/#740-add-static-assert-with-auto-message Feb 22, 2024
58 checks passed
@jwellbelove
Copy link
Contributor

I've just managed to get round to looking at this pull request and I noticed that it has a lot of 'co-authors', one at least involved with Linux. Has some of this change been copied from GPL code?

Co-authored-by: John Wellbelove [email protected]
Co-authored-by: David Hebbeker [email protected]
Co-authored-by: Linus Torvalds [email protected]
Co-authored-by: Zhaolei [email protected]
Co-authored-by: John Wellbelove [email protected]
Co-authored-by: Soma Veszelovszki [email protected]
Co-authored-by: Andreas [email protected]
Co-authored-by: Andreas Pelczer [email protected]
Co-authored-by: H1MSK [email protected]
Co-authored-by: jmartens-42 [email protected]
Co-authored-by: Josh [email protected]
Co-authored-by: John Wellbelove [email protected]

@dhebbeker
Copy link
Contributor Author

The branch contains some commits which were not supposed to be merged. A rebase is required to remove those, hence I did not mark the pull request as ready for merge.

I was not able to finish this pull request as I was not able to use the build pipeline to test the changes (see #784).

The only relevant changes for this pull request is the range including [7771cf3 ... ba53a39] (see comparison with parent). Those commits were authored my me.

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

Successfully merging this pull request may close these issues.

6 participants