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

            Bug ID: 91525
           Summary: ICE (Segmentation Fault) on a bool conversion operator
                    with concepts
           Product: gcc
           Version: 8.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de
  Target Milestone: ---

The following code segfaults on gcc 7 and gcc 8.

It seems to be fixed in gcc 9, but a variant of the following code still
segfault on gcc 9 and 10.

```c++
#include <functional>
#include <iostream>
namespace ranges {
struct view_interface {
  template < bool = true > operator bool();
#if 1
  template < bool B = true> requires false operator bool(); // ICE on gcc <= 10
#elif 1
  template < bool B = true> requires false explicit operator bool(); // ICE on
gcc <= 8. This code is working since gcc 9.
#else
  template < bool B = true, std::enable_if_t<B>> explicit operator bool(); // a
possible workaround
#endif
};

template < typename View > struct impl {
  template < typename... Ts, typename V = View >
  static auto bind(Ts... ts) -> decltype(V::bind((ts)...));
};

template < typename > struct view;
template < typename Fun > view< Fun > make_view(Fun);
template < typename View > struct view {
  template < typename Arg, typename Pipe >
  friend auto operator|(Arg, Pipe)
      -> decltype(Pipe::pipe(std::declval< Arg >, std::declval< Pipe >()));
  View view_;
  template < typename Rng, typename Vw > static auto pipe(Rng, Vw v) {
    return v.view_(0);
  }
  template < typename... Ts, typename V = View >
  auto operator()(Ts... ts)
      -> decltype(make_view(impl< V >::bind(view_, (ts)...)));
};
struct f {
  template < typename g > static auto bind(f h, g t) {
    return std::bind(h, std::placeholders::_1, t);
  }
  template < typename a, typename ValRng >
  auto operator()(a, ValRng) -> view_interface;
};
view< f > join;
} std::string e() {
  std::vector< std::string > extensions;
  std::string i;
  auto o = extensions | ranges::join(i);
  std::cout << o;
}

```

This will produce this error:

```terminal
> g++-9 -std=c++17 -fconcepts -c ice.cpp'
ice.cpp: In function ‘std::string e()’:
ice.cpp:53:16: internal compiler error: Segmentation fault
   53 |   std::cout << o;
      |                ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
```

Tested compiler versions are:

```terminal
> g++-7 --version
g++-7 (GCC) 7.4.1 20181207
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> g++-8 --version
g++-8 (GCC) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> g++-9 --version 
g++ (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> g++-git --version
g++-git (GCC) 10.0.0 20190709 (experimental)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

Reply via email to