Skip to content

Fix import std in clang++ #4488

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

Merged
merged 4 commits into from
Jul 7, 2025
Merged

Fix import std in clang++ #4488

merged 4 commits into from
Jul 7, 2025

Conversation

anonymouspc
Copy link
Contributor

When #define FMT_IMPORT_STD, {fmt} will do import std instead of #include <std...>. However this is currently broken on clang++. This PR fixes:

  1. clang++ cannot find memcpy, memcmp, abort when importing std. Fix it by adding #include <string.h> and #include <stdlib.h> in global module.
  2. include/fmt/std.h uses std::__bit_const_reference which is not exported by libc++ and cannot be found. Guard it by macros.

BTW, we can import C std symbols by import std.compat, and in this case we do not need the <limits.h>, <stdint.h>... as well. So that I add an optional FMT_IMPORT_STD_COMPAT macro to tell {fmt} whether import std.compat.

Thank you!

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. The fixes LGTM but I don't think we need to add another configuration macro (FMT_IMPORT_STD_COMPAT).

@anonymouspc
Copy link
Contributor Author

Thanks for the PR. The fixes LGTM but I don't think we need to add another configuration macro (FMT_IMPORT_STD_COMPAT).

Okay, I've reverted that :)

@anonymouspc anonymouspc requested a review from vitaut July 7, 2025 15:09
@vitaut vitaut merged commit 20c8fda into fmtlib:master Jul 7, 2025
41 checks passed
@vitaut
Copy link
Contributor

vitaut commented Jul 7, 2025

Merged, thanks!

@vitaut vitaut changed the title Fix import std in clang++, and add options for import std.compat Fix import std in clang++ Jul 7, 2025
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