fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
20.56k stars 2.46k forks source link

Does not compile with the FMT_PEDANTIC=ON and FMT_WERROR=ON options #3910

Closed pavard closed 6 months ago

pavard commented 6 months ago

Subj. ArchLinux gcc: 13.2.1 glibc: 2.39

In file included from /usr/include/stdio.h:44,
                 from /usr/include/c++/13.2.1/cstdio:42,
                 from /usr/include/c++/13.2.1/ext/string_conversions.h:45,
                 from /usr/include/c++/13.2.1/bits/basic_string.h:4097,
                 from /usr/include/c++/13.2.1/string:54,
                 from /usr/include/c++/13.2.1/bits/locale_classes.h:40,
                 from /usr/include/c++/13.2.1/locale:41,
                 from /home/pavard/work/core/external/build/fmt/fmt_build-prefix/src/fmt_build/include/fmt/format-inl.h:18,
                 from /home/pavard/work/core/external/build/fmt/fmt_build-prefix/src/fmt_build/src/format.cc:8:
In function «int putc_unlocked(int, FILE*)»,
    inlined from «void fmt::v10::detail::glibc_file<F>::init_buffer() [с F = _IO_FILE]» at /home/pavard/work/core/external/build/fmt/fmt_build-prefix/src/fmt_build/include/fmt/format-inl.h:1495:18,
    inlined from «fmt::v10::detail::file_print_buffer::file_print_buffer(FILE*)» at /home/pavard/work/core/external/build/fmt/fmt_build-prefix/src/fmt_build/include/fmt/format-inl.h:1630:22,
    inlined from «void fmt::v10::vprint_locked(FILE*, string_view, format_args)» at /home/pavard/work/core/external/build/fmt/fmt_build-prefix/src/fmt_build/include/fmt/format-inl.h:1687:46:
/usr/include/bits/stdio.h:103:10: ошибка: переход по пустому указателю [-Werror=null-dereference]
  103 |   return __putc_unlocked_body (__c, __stream);
      |          ^~~~~~~~~~~~~~~~~~~~
cc1plus: все предупреждения считаются ошибками
make[8]: *** [CMakeFiles/fmt.dir/build.make:76: CMakeFiles/fmt.dir/src/format.cc.o] Ошибка 1
make[7]: *** [CMakeFiles/Makefile2:83: CMakeFiles/fmt.dir/all] Ошибка 2
make[6]: *** [Makefile:156: all] Ошибка 2
vitaut commented 6 months ago

Thanks for reporting but FMT_PEDANTIC and FMT_WERROR are internal {fmt}'s options used in CI and not supposed to be used externally.

pavard commented 6 months ago

Maybe it would be possible to make an edit like this, please (fmt/format-inl.h:1493):

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnull-dereference"
    // Force buffer initialization by placing and removing a char in a buffer.
    putc_unlocked(0, this->file_);
#pragma GCC diagnostic pop
vitaut commented 6 months ago

Suppressing this false positive with a pragma is a bit messy but maybe it could be done in a cleaner way, e.g. using assume: https://github.com/fmtlib/fmt/blob/4e8640ed90ac8751d4a8ca500b893cc8c4bb9668/include/fmt/format.h#L484

It also seems weird that gcc complains about the file stream pointer being null because it is being dereference here: https://github.com/fmtlib/fmt/blob/4e8640ed90ac8751d4a8ca500b893cc8c4bb9668/include/fmt/format-inl.h#L1493