public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/95833] New: Incorrect static_assert in std::reduce overload taking a binary functor
@ 2020-06-23  7:20 eugns.p at gmail dot com
  2021-05-15  8:56 ` [Bug libstdc++/95833] " TonyELewis at hotmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: eugns.p at gmail dot com @ 2020-06-23  7:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95833
           Summary: Incorrect static_assert in std::reduce overload taking
                    a binary functor
           Product: gcc
           Version: 10.0
               URL: https://stackoverflow.com/q/62499765
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eugns.p at gmail dot com
  Target Milestone: ---

Created attachment 48773
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48773&action=edit
Preprocessed code for minimal example

The std::reduce overload that takes a binary functor

template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
_Tp reduce(_InputIterator, _InputIterator, _Tp, _BinaryOperation);

(defined here:
https://github.com/gcc-mirror/gcc/blob/releases/gcc-10/libstdc%2B%2B-v3/include/std/numeric#L236)

contains an incorrect static assertion:

static_assert(is_convertible_v<value_type, _Tp>);

There is no such requirement in the standard. This static assert causes a
compilation failure of the following minimal example:

#include <iostream>
#include <array>
#include <numeric>
#include <cstring>

struct StringLength {
    auto operator()(const char* l, std::size_t r) const {
        return std::strlen(l) + r;
    }

    auto operator()(std::size_t l, const char* r) const {
        return l + std::strlen(r);
    }

    auto operator()(const char* l, const char* r) const {
        return std::strlen(l) + std::strlen(r);
    }

    auto operator()(std::size_t l, std::size_t r) const {
        return l + r;
    }
};

int main() {
    std::array<const char*, 3> arr{"A", "B", "C"};
    std::cout << std::reduce(arr.begin(), arr.end(), std::size_t{},
StringLength{});
}

https://godbolt.org/z/Av3iY9

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-06-19  7:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23  7:20 [Bug libstdc++/95833] New: Incorrect static_assert in std::reduce overload taking a binary functor eugns.p at gmail dot com
2021-05-15  8:56 ` [Bug libstdc++/95833] " TonyELewis at hotmail dot com
2021-05-15 21:17 ` redi at gcc dot gnu.org
2021-05-16  8:41 ` TonyELewis at hotmail dot com
2021-06-18 13:50 ` redi at gcc dot gnu.org
2021-06-18 14:06 ` cvs-commit at gcc dot gnu.org
2021-06-18 15:55 ` cvs-commit at gcc dot gnu.org
2021-06-18 17:46 ` cvs-commit at gcc dot gnu.org
2021-06-18 20:57 ` cvs-commit at gcc dot gnu.org
2021-06-18 20:58 ` redi at gcc dot gnu.org
2021-06-19  7:29 ` TonyELewis at hotmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).