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

            Bug ID: 102777
           Summary: Error when requires expressions with parameter pack
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ispavlick at gmail dot com
  Target Milestone: ---

// clang compiles without errors.
#include <tuple>
#include <type_traits>
#include <iostream>
using namespace std;

template <typename T>
constexpr bool check_visitor = []<size_t ...I>(index_sequence<I...>){
            return ((requires (tuple_element_t<I, T> fun)
                                        {{fun(3)}->same_as<void>;}) && ...);
}(make_index_sequence<tuple_size_v<T>>{});

int main() {
        auto f1 = [](int) {};
        auto f2 = [](int) {};
        static_assert(check_visitor<tuple<decltype(f1), decltype(f2)>>);
}


$ g++ -std=c++20 1.cpp
1.cpp: In lambda function:
1.cpp:9:22: error: operand of fold expression has no unexpanded parameter packs
    9 |             return ((requires (tuple_element_t<I, T> fun)
      |                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 |                                         {{fun(3)}->same_as<void>;}) &&
...);
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.cpp: In instantiation of ‘constexpr const bool
check_visitor<std::tuple<main()::<lambda(int)>, main()::<lambda(int)> > >’:
1.cpp:16:16:   required from here
1.cpp:11:2: error: void value not ignored as it ought to be
    8 | constexpr bool check_visitor = []<size_t ...I>(index_sequence<I...>){
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    9 |             return ((requires (tuple_element_t<I, T> fun)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 |                                         {{fun(3)}->same_as<void>;}) &&
...);
      |                                        
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   11 | }(make_index_sequence<tuple_size_v<T>>{});
      | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.cpp: In function ‘int main()’:
1.cpp:16:23: error: non-constant condition for static assertion
   16 |         static_assert(check_visitor<tuple<decltype(f1),
decltype(f2)>>);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to