[Bug tree-optimization/112307] Segmentation fault with -O1 -fcode-hoisting

2024-03-08 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112307

--- Comment #10 from Raffael Casagrande  ---
(In reply to Jonathan Wakely from comment #9)

Thanks very much! I missed the part with the trivial copy constructor and
learned again an important lesson. That explains why it works when I defined
the copy constructors manually.

[Bug tree-optimization/112307] Segmentation fault with -O1 -fcode-hoisting

2024-03-08 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112307

--- Comment #7 from Raffael Casagrande  ---
@Jonathan Wakely Thanks very much for the detailed analysis. But there is one
point which I don't understand:

> BUT, the self-referential pointer is set to the address of the range_ member 
> before the return value is copied, and so goes out of scope when that object
> is copied via registers and then copied again into the automatic variable
> in main().


I can't follow/understand how Next() is called before the return value is
copied.
If we look at the constructor of EnumeratorRange, we see that `enumerator_` is
initialized before end_reached_.

And afterwards the enumerator_ is not moved/copied anymore because of copy
elision? This can be verified by adding some extra print statements to the
copy/move constructor of Enumerator.

[Bug c++/112307] New: Segmentation fault with -O1 -fcode-hoisting

2023-10-31 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112307

Bug ID: 112307
   Summary: Segmentation fault with -O1 -fcode-hoisting
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

*Affected Versions*: 10.0 - current (14.0.0 20231031). Earlier versions cannot
compile the code because it uses c++20.

*System*: Linux
*Command Line*: g++ main.cc -std=c++20 -O1 -fcode-hoisting

*Compiler Output*:

:48:87: warning: friend declaration 'bool operator==(const
EnumeratorRange::Sentinel&, const
EnumeratorRange::Iterator&)' declares a non-template function
[-Wnon-template-friend]
   48 | friend auto operator==(const Sentinel& /*unused*/, const Iterator&
i) noexcept -> bool;
  |
  ^~~~
:48:87: note: (if this is not what you intended, make sure the function
template has already been declared and add '<>' after the function name here)

*Runtime Output*: Segmentation fault, "boundary" is printed many times.


*Source File*:
#include 
#include 
#include 
#include 



template 
class EnumeratorRange {
 public:
  struct Sentinel {
Sentinel() noexcept = default;
Sentinel(const Sentinel&) noexcept = default;
Sentinel(Sentinel&&) noexcept = default;
auto operator=(const Sentinel&) noexcept -> Sentinel& = default;
auto operator=(Sentinel&&) noexcept -> Sentinel& = default;
~Sentinel() noexcept = default;
  };

  class Iterator {
   public:
using value_type = typename ENUMERATOR::value_type;
using difference_type = std::ptrdiff_t;
explicit Iterator(EnumeratorRange* range) : range_(range) {}
Iterator() noexcept = default;
Iterator(const Iterator&) = delete;
Iterator(Iterator&&) noexcept = default;
~Iterator() noexcept = default;
auto operator=(const Iterator&) = delete;
auto operator=(Iterator&&) noexcept -> Iterator& = default;

auto operator*() const noexcept {
  assert(!range_->end_reached_);

  return *range_->enumerator_;
}
auto operator++() noexcept -> Iterator& {
  assert(!range_->end_reached_);
  range_->end_reached_ = !range_->enumerator_.Next();
  return *this;
}

auto operator++(int) noexcept -> void { ++*this; }

   private:
EnumeratorRange* range_;

friend auto operator==(const Sentinel& /*unused*/, const Iterator& i)
noexcept -> bool;
  };

  explicit EnumeratorRange(ENUMERATOR&& e)
  : enumerator_(std::move(e)), end_reached_(!enumerator_.Next()) {}

  auto begin() const noexcept {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return Iterator(const_cast(this));
  }

  auto end() const noexcept { return Sentinel(); }

 private:
  ENUMERATOR enumerator_;
  bool end_reached_;

  friend auto operator==(const Sentinel&, const Iterator& i) noexcept -> bool {
return i.range_->end_reached_;
  }
  friend auto operator==(const Iterator& i, const Sentinel& s) noexcept -> bool
{ return s == i; }
  friend auto operator!=(const Sentinel& s, const Iterator& i) noexcept -> bool
{
return !(s == i);
  }
  friend auto operator!=(const Iterator& i, const Sentinel& s) noexcept -> bool
{
return !(s == i);
  }
};

class Intersection {
 public:

  auto Boundary() const noexcept -> bool { return is_boundary_; }

 private:
  bool is_boundary_ = true;
};


class CompositeMesh {
 public:

  auto Intersections() const noexcept -> std::ranges::input_range auto;

};


auto CompositeMesh::Intersections() const noexcept -> std::ranges::input_range
auto {
  class Enumerator {
   public:
using wrapped_range_t = decltype(std::views::single(Intersection()));
explicit Enumerator(wrapped_range_t&& range) : range_(std::move(range)),
begin_{} {}

using value_type = Intersection;

auto operator*() const noexcept -> value_type { return *begin_.value(); }

auto Next() noexcept -> bool {
  if (!begin_.has_value()) {
auto b = range_.begin();
bool result = (b != range_.end());
begin_ = std::move(b);
return result;
  } else {
auto& b = *begin_;
if ((*b).Boundary()) {
  std::cout << "boundary" << std::endl;
}

++b;
return b != range_.end();
  }
}

   private:
wrapped_range_t range_;
std::optional> begin_;
  };

  return EnumeratorRange(Enumerator(std::views::single(Intersection(;
}

int main() {
  auto mesh = CompositeMesh();

  decltype(auto) intersections = mesh.Intersections();
  for (auto intersection : intersections) {
  }
}

*Additional Notes*
- It works if we use `-O2` (which includes -fcode-hoisting)
- Godbolt: https://godbolt.org/z/1PqTKz33Y
- One can disable the following compiler options from `-O1` and still reproduce
the bug: -fno-auto-inc-dec 

[Bug c++/106309] New: ICE: error reporting routines re-entered

2022-07-14 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106309

Bug ID: 106309
   Summary: ICE: error reporting routines re-entered
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

I tried for over 2 hours to get a minimal test case but it is quite involved
and for now I give up. I've created a file with the preprocessed source using
`-freport-bug` and uploaded it to my dropbox:
https://www.dropbox.com/s/oxx299jhx7yi3b2/ccFsUsUT.out?dl=0 . Unfortunately the
file is 11Kb large so I cannot attach it here in bugzilla.

The error message that GCC produces is the following:
--
‘
internal compiler error: error reporting routines re-entered.
0x1b9ca82 warning_at(unsigned int, int, char const*, ...)
???:0
0x95317a shorten_compare(unsigned int, tree_node**, tree_node**, tree_node**,
tree_code*)
???:0
0x915581 cp_build_binary_op(op_location_t const&, tree_code, tree_node*,
tree_node*, int)
???:0
0x75f23c build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
???:0
0x90c45f build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
???:0
0x8b00a7 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
???:0
0x78f993 constraints_satisfied_p(tree_node*, tree_node*)
???:0
0x8b9f69 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x1ba82ac pp_format(pretty_printer*, text_info*)
???:0
0x1ba9830 pp_verbatim(pretty_printer*, char const*, ...)
???:0
0x1b9bfa1 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
???:0
0x1b9cd76 error(char const*, ...)
???:0
0x8ade04 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int)
???:0
0x924d0a build_functional_cast(unsigned int, tree_node*, tree_node*, int)
???:0
0x8b1c54 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
???:0
0x8c0d29 instantiate_decl(tree_node*, bool, bool)
???:0
0x8d575b instantiate_pending_templates(int)
???:0
0x7db28f c_parse_final_cleanups()
???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See  for instructions.
--

As far as I can tell, the file which I uploaded to Dropbox should contain all
the information which is necessary to reproduce the bug (e.g. command line and
precompiled sources).
If you need more information to reproduce the bug, please let me know.

[Bug c++/104788] New: ICE

2022-03-04 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104788

Bug ID: 104788
   Summary: ICE
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

The following simple program produces an internal compiler error when compiled
with "-std=c++20" (problem seems to be fixed in current trunk 12.0!):

#include 
#include 

template 
class OpenFoamReader {
 public:
  OpenFoamReader() {
auto z = []() {
  struct Connection {
std::uint32_t end_point;
auto operator<=>(const Connection&) const noexcept ->
std::strong_ordering = default;
  };
  std::vector connections;

  // sort connections
  std::ranges::sort(connections);
};
  }
};

int main() {
OpenFoamReader reader;
}


Error message:

In file included from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/move.h:57,
 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_pair.h:59,
 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/utility:70,
 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/algorithm:60,
 from :1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits: In
instantiation of 'constexpr const bool std::is_invocable_v::OpenFoamReader()Connection&,
OpenFoamReader::OpenFoamReader()Connection&>':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/concepts:338:25:  
required by substitution of 'template 
requires (random_access_range<_Range>) &&
(sortable)())),
_Comp, _Proj>) constexpr std::ranges::borrowed_iterator_t<_Range>
std::ranges::__sort_fn::operator()(_Range&&, _Comp, _Proj) const [with _Range =
std::vector::OpenFoamReader()Connection,
std::allocator::OpenFoamReader()Connection>
>&; _Comp = std::ranges::less; _Proj = std::identity]'
:16:24:   required from 'OpenFoamReader::OpenFoamReader()
[with MESH_FACTORY = int]'
:22:25:   required from here
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:3001:27:
internal compiler error: Segmentation fault
 3001 | inline constexpr bool is_invocable_v = is_invocable<_Fn,
_Args...>::value;
  |   ^~
0x1786229 internal_error(char const*, ...)
???:0
0x806d30 stmts_are_full_exprs_p()
???:0
0x700b81 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
???:0
0x7e02f3 instantiate_decl(tree_node*, bool, bool)
???:0
0x70a613 maybe_instantiate_decl(tree_node*)
???:0
0x7f4881 lookup_and_finish_template_variable(tree_node*, tree_node*, int)
???:0
0x6c532a constraints_satisfied_p(tree_node*, tree_node*)
???:0
0x7f7487 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
???:0
0x695371 build_op_call(tree_node*, vec**, int)
???:0
0x80ae32 finish_call_expr(tree_node*, vec**, bool,
bool, int)
???:0
0x7f2e86 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0x7e02f3 instantiate_decl(tree_node*, bool, bool)
???:0
0x7fb69b instantiate_pending_templates(int)
???:0
0x70cd4d c_parse_final_cleanups()
???:0

[Bug c++/104594] New: narrowing conversion of -1 to unsigned char at compile time not detected

2022-02-18 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104594

Bug ID: 104594
   Summary: narrowing conversion of -1 to unsigned char at compile
time not detected
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

The current gcc trunk compiles the following piece of code:

template 
concept Geometry = (DIM_FROM == -1);

template 
requires Geometry
auto GaussNewton(const INIT& init) -> void {}

template
struct X {
  static constexpr int n = N;
};

int main() { GaussNewton(X<-1>{}); }
--

I think this should NOT compile since it entails a narrowing conversion of -1
to an unsigned char type at compile time. Clang as well as MSVC fail to compile
the code.
(In many other cases, gcc also fails to compile if such a narrowing conversion
happens at compile time.)

[Bug c++/102748] New: static_assert on concept leads to undefined reference

2021-10-14 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102748

Bug ID: 102748
   Summary: static_assert on concept leads to undefined reference
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

Try to compile and link the following simple program with `-std=c++20`:
---
template 
auto ForEachGuided(RANGE&& range, CALLABLE&& c) {
  range.begin();
}

struct RandomAccessRangeAT {
  void begin() const noexcept;
};

template 
concept FESpaceFactory = requires(const FE_SPACE_FACTORY& fe_space_factory,
  const RandomAccessRangeAT& range) {
  {fe_space_factory(range)};
};

int main() {
  auto fes_provider = [](auto&& range) {
ForEachGuided(range, []() {});
  };
  static_assert(FESpaceFactory);
}
--

Compilation will work, but during linking we get the error message:
"undefined reference to `RandomAccessRangeAT::begin() const'"

As soon as we apply some optimization flags, the linking error vanishes.
Also clang doesn't have this problem...

[Bug libstdc++/102181] std::advance and std::views::iota don't work

2021-09-02 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181

--- Comment #3 from Raffael Casagrande  ---
thanks for the fast response. I can switch over to std::ranges::advance.

MSVC compiles the snippet without problems...

[Bug libstdc++/102181] New: std::advance and std::views::iota don't work

2021-09-02 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181

Bug ID: 102181
   Summary: std::advance and std::views::iota don't
work
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

The following simple program doesn't compile:

#include 

int main() {
  using type = std::int64_t; // using type = int works!
  auto v = std::ranges::iota_view(static_cast(0),
static_cast(100));
  auto b = v.begin();
  std::advance(b, static_cast(1));
}


gcc version: 12.0.0 20210901 (experimental)

Error messages:

/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:
In instantiation of 'constexpr void std::advance(_InputIterator&, _Distance)
[with _InputIterator = std::ranges::iota_view::_Iterator;
_Distance = long int]':
:7:15:   required from here
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:21:
error: no matching function for call to '__advance(std::ranges::iota_view::_Iterator&, std::__iterator_traits::_Iterator, void>::difference_type&,
std::__iterator_traits::_Iterator,
void>::iterator_category)'
  207 |   std::__advance(__i, __d, std::__iterator_category(__i));
  |   ~~^
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:148:5:
note: candidate: 'template constexpr
void std::__advance(_InputIterator&, _Distance, std::input_iterator_tag)'
  148 | __advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
  | ^
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:148:5:
note:   template argument deduction/substitution failed:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:56:
note:   cannot convert 'std::__iterator_category::_Iterator>((*(const std::ranges::iota_view::_Iterator*)(& __i)))' (type
'std::__iterator_traits::_Iterator,
void>::iterator_category' {aka 'std::output_iterator_tag'}) to type
'std::input_iterator_tag'
  207 |   std::__advance(__i, __d, std::__iterator_category(__i));
  |^
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:159:5:
note: candidate: 'template
constexpr void std::__advance(_BidirectionalIterator&, _Distance,
std::bidirectional_iterator_tag)'
  159 | __advance(_BidirectionalIterator& __i, _Distance __n,
  | ^
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:159:5:
note:   template argument deduction/substitution failed:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:56:
note:   cannot convert 'std::__iterator_category::_Iterator>((*(const std::ranges::iota_view::_Iterator*)(& __i)))' (type
'std::__iterator_traits::_Iterator,
void>::iterator_category' {aka 'std::output_iterator_tag'}) to type
'std::bidirectional_iterator_tag'
  207 |   std::__advance(__i, __d, std::__iterator_category(__i));
  |^
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:175:5:
note: candidate: 'template
constexpr void std::__advance(_RandomAccessIterator&, _Distance,
std::random_access_iterator_tag)'
  175 | __advance(_RandomAccessIterator& __i, _Distance __n,
  | ^
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:175:5:
note:   template argument deduction/substitution failed:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:56:
note:   cannot convert 'std::__iterator_category::_Iterator>((*(const std::ranges::iota_view::_Iterator*)(& __i)))' (type
'std::__iterator_traits::_Iterator,
void>::iterator_category' {aka 'std::output_iterator_tag'}) to type
'std::random_access_iterator_tag'
  207 |   std::__advance(__i, __d, std::__iterator_category(__i));
  |^

[Bug gcov-profile/100744] Undefined symbol __gcov_flush when building with -fprofile-arcs

2021-05-24 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100744

--- Comment #2 from Raffael Casagrande  ---
Oh, I didn't notice this change. Thanks for pointing this out!

[Bug gcov-profile/100744] New: Undefined symbol __gcov_flush when building with -fprofile-arcs

2021-05-24 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100744

Bug ID: 100744
   Summary: Undefined symbol __gcov_flush when building with
-fprofile-arcs
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Trying to link the following simple program with `-fprofile-arcs` fails:
--
extern "C" void __gcov_flush();

int main() {
  __gcov_flush();
}
--
Command line: `g++ source.cc -fprofile-arcs`

This used to work with gcc-10.3. It seems to be a regression of gcc-11.1/trunk?

[Bug c++/100739] New: Definition of function template doesn't match declaration

2021-05-24 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100739

Bug ID: 100739
   Summary: Definition of function template doesn't match
declaration
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

The following code fails to compile with the newest gcc (gcc 12.0.0 20210523):
-
#include 
#include 

template 
requires std::integral using debug_t = T;

template
struct X {
  auto operator()(std::integral auto const& i) const ->
std::array,1>;
};

template
auto X::operator()(std::integral auto const& i) const ->
std::array,1>{

};
--
The error message is:
--
:13:6: error: no declaration matches 'std::array,
1> X::operator()(const auto:4&) const'
   13 | auto X::operator()(std::integral auto const& i) const ->
std::array,1>{
  |  ^~~~
:9:8: note: candidate is: 'template template 
requires  integral std::array, 1>
X::operator()(const auto:3&) const'
9 |   auto operator()(std::integral auto const& i) const ->
std::array,1>;
  |^~~~
:8:8: note: 'struct X' defined here
8 | struct X {
  |^
--

If we further simplify the code in one of the following ways, the problem
disappears:
1) If we remove the `std::array<...>`
2) If we remove the requires clause in the definition of debug_t

[Bug c++/100502] New: ICE in enforce_access at cp/semantics.c:368

2021-05-10 Thread raffael at casagrande dot ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100502

Bug ID: 100502
   Summary: ICE in enforce_access at cp/semantics.c:368
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: raffael at casagrande dot ch
  Target Milestone: ---

Compile the following source file:

#include 

template 
struct EnumeratorRange {
  struct Iterator {
EnumeratorRange* range_;

friend auto operator==(const Iterator&, const Iterator& i) noexcept -> bool
{
  return i.range_->end_reached_;
}
  };

 private:
  bool end_reached_;
};

with current trunk (V12.0.0 20210509) or with gcc 11.1 on Ubuntu 20.04 using
the command line "g++-11 -std=c++20 main.cc". This produces the following ICE:
Compiler stderr

: In function 'bool operator==(const EnumeratorRange<
 >::Iterator&, const EnumeratorRange<
 >::Iterator&)':
:9:24: internal compiler error: in enforce_access, at
cp/semantics.c:368
9 |   return i.range_->end_reached_;
  |^~~~
0x1d07289 internal_error(char const*, ...)
???:0
0x6bddc3 fancy_abort(char const*, int, char const*)
???:0
0x97a0ba perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int,
access_failure_info*)
???:0
0x971ece lookup_member(tree_node*, tree_node*, int, bool, int,
access_failure_info*)
???:0
0x9ed934 finish_class_member_access_expr(cp_expr, tree_node*, bool, int)
???:0
0x8e4d1d c_parse_file()
???:0
0xa653b2 c_common_parse_file()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

See also https://godbolt.org/z/PeGMvKeqd