Skip to content

Replace non-standard ABS macro for C++23 compatibility#516

Closed
xroche wants to merge 1 commit into
DataDog:mainfrom
algolia:feat/cxx23-compat
Closed

Replace non-standard ABS macro for C++23 compatibility#516
xroche wants to merge 1 commit into
DataDog:mainfrom
algolia:feat/cxx23-compat

Conversation

@xroche

@xroche xroche commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary

The ABS macro in logger.hpp uses typeof and a GCC statement-expression ({...}), both rejected by -std=c++23 without GNU extensions. Replace with a constexpr function.

Builds cleanly with both -std=gnu++20 (default) and -std=c++23.

🤖 Generated with Claude Code

…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
xroche force-pushed the feat/cxx23-compat branch from 8a09b22 to 54e333f Compare March 19, 2026 13:43
@xroche
xroche marked this pull request as ready for review March 19, 2026 13:45
Comment thread include/logger.hpp
const typeof(__x) _x = (__x); \
_x < 0 ? -1 * _x : _x; \
})
constexpr int ddprof_abs(int x) { return x < 0 ? -x : x; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice use of constexpr function for log levels in macros

Comment thread include/logger.hpp
do { \
if (unlikely(LOG_is_logging_enabled_for_level(level))) { \
olprintfln(ABS(level), -1, __VA_ARGS__); \
olprintfln(ddprof_abs(level), -1, __VA_ARGS__); \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dang, forgot the format before push indeed!

@r1viollet

Copy link
Copy Markdown
Collaborator

closing in favour of #517

@r1viollet r1viollet closed this Mar 19, 2026
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.

2 participants