Replace non-standard ABS macro for C++23 compatibility#516
Closed
xroche wants to merge 1 commit into
Closed
Conversation
…atibility
The ABS macro in logger.hpp used typeof (GNU extension) and a
statement-expression ({...}), both rejected by strict C++23 mode.
Replace with a constexpr function that works under any C++ standard.
This lets ddprof compile when a parent project or Conan toolchain
injects -std=c++23 without GNU extensions.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
xroche
force-pushed
the
feat/cxx23-compat
branch
from
March 19, 2026 13:43
8a09b22 to
54e333f
Compare
xroche
marked this pull request as ready for review
March 19, 2026 13:45
r1viollet
reviewed
Mar 19, 2026
| const typeof(__x) _x = (__x); \ | ||
| _x < 0 ? -1 * _x : _x; \ | ||
| }) | ||
| constexpr int ddprof_abs(int x) { return x < 0 ? -x : x; } |
Collaborator
There was a problem hiding this comment.
Nice use of constexpr function for log levels in macros
r1viollet
reviewed
Mar 19, 2026
| do { \ | ||
| if (unlikely(LOG_is_logging_enabled_for_level(level))) { \ | ||
| olprintfln(ABS(level), -1, __VA_ARGS__); \ | ||
| olprintfln(ddprof_abs(level), -1, __VA_ARGS__); \ |
Collaborator
There was a problem hiding this comment.
I had to redo the commit as there was a format issue here.
you can run make-format in the ubuntu 24 container, that should ensure PRs are ready
New PR is here:
#517
Contributor
Author
There was a problem hiding this comment.
Dang, forgot the format before push indeed!
Collaborator
|
closing in favour of #517 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
ABSmacro inlogger.hppusestypeofand a GCC statement-expression({...}), both rejected by-std=c++23without GNU extensions. Replace with aconstexprfunction.Builds cleanly with both
-std=gnu++20(default) and-std=c++23.🤖 Generated with Claude Code