FMT_INLINE works differently than using __attribute__((always_inline))
FMT_INLINE works differently than using __attribute__((always_inline)) directly.
Reproduce
cmake: cmake -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release .. gcc: c++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
int main() {
auto res = fmt::format(FMT_COMPILE("{} {} {}"), 1, 2, 3);
std::cout << res << std::endl;
}
We can see that there is a function call in the asm of the target binary
130bb: e8 73 00 00 00 call 13133 <std::__cxx11::basic_string<main::{lambda()#1}::operator()() const::FMT_COMPILE_STRING::char_t ype, std::char_traits<main::{lambda()#1}::operator()() const::FMT_COMPILE_STRING::char_type>, std::allocator<main::{lambda()#1}::operator()() c onst::FMT_COMPILE_STRING::char_type> > fmt::v11::format<main::{lambda()#1}::operator()() const::FMT_COMPILE_STRING, int, int, int, 0>(main::{la mbda()#1}::operator()() const::FMT_COMPILE_STRING const&, int&&, int&&, int&&)>
After changing FMT_INLINE std::basic_string<typename S::char_type> format(const S&, Args&&... args) to __attribute__((always_inline)) std::basic_string<typename S::char_type> format(const S&,Args&&... args), we can find that the format function has been inline.
extra info
I try to use c++ -E && c++ -c to compare the file after pre-compiled or compiled(as a single object file), but there is no difference between them. We can see that the function signature is marked as inline like inline __attribute__((always_inline)) std::basic_string<typename S::char_type> format no matter FMT_INLINE or attribute((always_inline)) we use.