public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96575] New: std::ranges::sort is not usable as a 'constexpr' function when saving its return value in lambda function
@ 2020-08-12  1:23 hewillk at gmail dot com
  2020-08-12  7:33 ` [Bug c++/96575] " hewillk at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hewillk at gmail dot com @ 2020-08-12  1:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96575
           Summary: std::ranges::sort is not usable as a 'constexpr'
                    function when saving its return value in lambda
                    function
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

(https://godbolt.org/z/W8zx58)

#include <array>
#include <algorithm>

constexpr auto f(auto algo) {
  return [=] {
    // this one is okay
    // algo(std::array{1, 0});
    // this one is also okay
    // auto it = algo(std::array{0, 1});
    auto it = algo(std::array{1, 0});
    return 0;
  }();
}

int main()
{
  static_assert(f(std::ranges::sort) == 0); 
}


This fails on gcc 10.2 and trunk with:

<source>:13:23: error: 'constexpr auto f(auto:16) [with auto:16 =
std::ranges::__sort_fn]' called in a constant expression
   13 |   constexpr auto i = f(std::ranges::sort);
      |                      ~^~~~~~~~~~~~~~~~~~~
<source>:4:16: note: 'constexpr auto f(auto:16) [with auto:16 =
std::ranges::__sort_fn]' is not usable as a 'constexpr' function because:
    4 | constexpr auto f(auto algo) {
      |                ^
<source>:8:8: error: call to non-'constexpr' function
'f<std::ranges::__sort_fn>::<lambda()>'
    5 |       return [=] {
      |              ~~~~~
    6 |         auto it = algo(std::array{1, 0});
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    7 |           return 0;
      |           ~~~~~~~~~
    8 |       }();
      |       ~^~
<source>:5:14: note: 'f<std::ranges::__sort_fn>::<lambda()>' is not usable as a
'constexpr' function because:
    5 |       return [=] {

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

end of thread, other threads:[~2020-10-22 11:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12  1:23 [Bug c++/96575] New: std::ranges::sort is not usable as a 'constexpr' function when saving its return value in lambda function hewillk at gmail dot com
2020-08-12  7:33 ` [Bug c++/96575] " hewillk at gmail dot com
2020-10-08  3:52 ` ppalka at gcc dot gnu.org
2020-10-22 11:34 ` cvs-commit at gcc dot gnu.org
2020-10-22 11:51 ` ppalka at gcc dot gnu.org

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).