Skip to content

Disable std::exception formatter when exceptions are disabled. - #4904

Open
cjacek wants to merge 1 commit into
fmtlib:mainfrom
cjacek:no-exceptions
Open

Disable std::exception formatter when exceptions are disabled.#4904
cjacek wants to merge 1 commit into
fmtlib:mainfrom
cjacek:no-exceptions

Conversation

@cjacek

@cjacek cjacek commented Aug 29, 2026

Copy link
Copy Markdown

Fixes building with Clang 20 and older with -fno-exceptions, which treats try/catch usage as an error.

Fixes FEX builds: FEX-Emu/FEX#5870

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR, but I don’t think we should disable the std::exception formatter itself. Instead, please disable only the minimal part that relies on try/catch. Also, could you post the full compiler error message?

…tions are disabled.

Fixes building with Clang 20 and older with -fno-exceptions, which treats
try/catch usage as an error.
@cjacek

cjacek commented Sep 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review. The new version disables only minimal part of std::exception formatter. for exception_ptr, it seems that there would be nothing left if I did that. I also considered using FMT_TRY/FMT_CATCH, but that would just be broken with disabled exceptions.

The error message is:

fmt/include/fmt/std.h:685:9: error: cannot use 'try' with exceptions disabled
fmt/include/fmt/std.h:704:5: error: cannot use 'try' with exceptions disabled

Here is a compiler explorer repro: https://godbolt.org/z/7jKncahEK

It's specific to usage in templates that's now allowed. Outside templates it's always an error.

Comment thread include/fmt/std.h
}
};

#if FMT_USE_EXCEPTIONS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Presence of std::exception_ptr doesn't depend on whether exceptions are enabled or disabled and in general we prefer not to make formatter availability depend on configuration. Let's move this to the format function and only guard try/catch block there giving "unknown exception" if exceptions are disabled.

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