https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116696

            Bug ID: 116696
           Summary: function template not considered constexpr even with
                    -fimplicit-constexpr
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

I was trying to implement constexpr std::format as cheaply as possible — by
using -fimplicit-constexpr instead of bothering to mark dozens (if not more)
functions constexpr. That mostly worked quite well. 

Oddly, there was one function template that did not get marked constexpr
implicitly, which was this one:
https://github.com/gcc-mirror/gcc/blob/8c01976b8e34eaa2483ab37d1bd18ebc5c8ada95/libstdc%2B%2B-v3/include/std/format#L736

You can see this on compiler explorer here: https://godbolt.org/z/xq1zvqPWh
(the function template in question is on line 733)

The example fails with:

<source>:1355:42: error: call to non-'constexpr' function '_Out
std::__format::__write_padded(_Out, std::basic_string_view<_CharT>, _Align,
std::size_t, char32_t) [with _Out = _Sink_iter<char>; _CharT = char;
std::size_t = long unsigned int]'
 1355 |           return __format::__write_padded(std::move(__out), __str,
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
 1356 |                                           __align, __nfill,
__fill_char);
      |                                          
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:734:5: note: '_Out std::__format::__write_padded(_Out,
std::basic_string_view<_CharT>, _Align, std::size_t, char32_t) [with _Out =
_Sink_iter<char>; _CharT = char; std::size_t = long unsigned int]' declared
here
  734 |     __write_padded(_Out __out, basic_string_view<_CharT> __str,
      |     ^~~~~~~~~~~~~~

Notably, there are lots of other function templates not marked constexpr in
this header that work just fine with -fimplicit-constexpr. Not sure what's
special about this one.

Reply via email to