Skip to content

Fix import std in clang++#4488

Merged
vitaut merged 4 commits intofmtlib:masterfrom
shyeyian:master
Jul 7, 2025
Merged

Fix import std in clang++#4488
vitaut merged 4 commits intofmtlib:masterfrom
shyeyian:master

Conversation

@shyeyian
Copy link
Copy Markdown

@shyeyian shyeyian commented Jul 6, 2025

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
Copy Markdown
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).

@shyeyian
Copy link
Copy Markdown
Author

shyeyian commented Jul 7, 2025

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 :)

@shyeyian shyeyian 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
Copy Markdown
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