KEMBAR78
Don't use __builtin_strlen · Issue #4423 · fmtlib/fmt · GitHub
Skip to content

Don't use __builtin_strlen #4423

@brevzin

Description

@brevzin

When upgrading {fmt}, b4d1d7f8e broke some of our usage. We had a place where we were building up a format string using a type like this:

template <size_t N>
struct fixed_string {
    char data[N] = {}; 

    constexpr fixed_string(char const (&m)[N]) {
        for (size_t i = 0; i != N; ++i) {
            data[i] = m[i];
        }
    }   
};

And trying to do something like:

static constexpr auto f = fixed_string("x={}");
fmt::print(f.data, 42);

This works on fmt 10.2.1 and 11.0, fails on trunk — after that commit, with:

/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h:543:31: error: '__builtin_strlen(((const char*)(& f.fixed_string<5>::data)))' is not a constant expression
  543 |       size_ = __builtin_strlen(detail::narrow(s));
      |               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

gcc says that __builtin_strlen isn't usable like this. Which... if they say so. But seems unlikely this will change, so I think {fmt} should also revert to previous usage.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions