-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Segfault when compiling with mixed -std options in gcc #2017
Comments
I think we have the same issue (fmt is installed via conan). The test case to reproduce: main.cpp #include <fmt/format.h>
#include <iostream>
int main()
{
std::cout << fmt::to_string(10.) << std::endl;
std::cout << fmt::format("{}", 10.) << std::endl;
} CMakeLists.txt
The cause of the issues is that the library code and our code are compiled with different versions of the standard. If I change the standard in the CMakeLists.txt above to be the same everything is OK. When I install the library in header-only mode the problem disappears too. The problem is in the line: Line 2000 in b268f88
The enclosing function is compiled twice with different standard. c++11: constexpr basic_format_specs() is not constexpr (can be checked with static_assert(fmt::detail::fill_t<char>::make()[0] == ' ', " ") that fails) so the dynamic initialization for the static variable is inlined.c++14 or later: In the client code the constructor of basic_format_specs is proper constexpr and compiler initializes the variable in compile time and places it in the read-only part of the data segment.In runtime the library code is called that tries to initialize static variable but the variable is read-only hence segfault. Honestly I don't know whose issue it is. :) Reproducable with gcc 9.3.1 and clang 9.0.1. |
I wasn't able to repro this on {fmt} 7.1.2 built from source and mixing standards is generally not recommended. That said a PR with a workaround would be welcome. |
Nevermind, it wasn't reproducing with clang. I did manage to repro with gcc-10. |
Bisected to 3c13a88. |
Worked around in f81c14a but please note that mixing different standard versions is probably a UB. |
My env:
I have a very simple usage like below:
The test case for this usage causes a segfault.
Here is the stack trace in the core dump I collected:
The text was updated successfully, but these errors were encountered: