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

            Bug ID: 122789
           Summary: [modules] ICE on invalid when tsubsting a parameter
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nshead at gcc dot gnu.org
            Blocks: 103524
  Target Milestone: ---

Ran into this when I started to reduce PR122699.

  // test.cpp
  import std;
  struct C {};
  inline void PtoVec() {
    int tag[5];
    tag | std::ranges::to<C>();
  }

$ g++ -std=c++23 -fmodules -S test.cpp
In file included from
/home/wreien/.local/include/c++/16.0.0/x86_64-pc-linux-gnu/bits/stdc++.h:89,
                 from /home/wreien/.local/include/c++/16.0.0/bits/std.cc:26,
of module std, imported at test.cpp:1:
/home/wreien/.local/include/c++/16.0.0/ranges: In instantiation of ‘constexpr
const bool std::ranges::__detail::__reservable_container<C>’:
required from ‘constexpr _Cont std::ranges::to(_Rg&&, _Args&& ...) [with _Cont
= C; _Rg = int (&)[5]; _Args = {}]’
/home/wreien/.local/include/c++/16.0.0/ranges:9421:23:
 9421 |                               &&
__detail::__reservable_container<_Cont>)
      |                                 
~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
recursively required by substitution of ‘template<class _Self, class _Range> 
requires  __adaptor_invocable<_Adaptor, _Range, typename
std::__like_impl<_Self&&, _Args&>::type ...> constexpr auto
std::ranges::views::__adaptor::_Partial<std::ranges::__detail::_To<C>
>::operator()(this _Self&&, _Range&&) [with _Self =
std::ranges::views::__adaptor::_Partial<std::ranges::__detail::_To<C> >; _Range
= int (&)[5]]’
/home/wreien/.local/include/c++/16.0.0/ranges:948:44:
  948 |       = requires { std::declval<_Adaptor>()(declval<_Args>()...); };
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
required by substitution of ‘template<class _Self, class _Range>  requires
(__is_range_adaptor_closure<_Self>) && (__adaptor_invocable<_Self, _Range>)
constexpr auto std::ranges::views::__adaptor::operator|(_Range&&, _Self&&)
[with _Self =
std::ranges::views::__adaptor::_Partial<std::ranges::__detail::_To<C> >; _Range
= int (&)[5]]’
/home/wreien/.local/include/c++/16.0.0/ranges:948:44:
required from here
test.cpp:7:28:
    7 |   tag | std::ranges::to<C>();
      |                            ^
/home/wreien/.local/include/c++/16.0.0/ranges:9361:21: internal compiler error:
tree check: expected tree that contains ‘decl minimal’ structure, have
‘error_mark’ in tsubst_expr, at cp/pt.cc:22331
 9361 |         __c.reserve(__n);
      |                     ^~~
0x3e7fa4e internal_error(char const*, ...)
        ../../gcc/gcc/diagnostic-global-context.cc:787
0x232dd7f tree_contains_struct_check_failed(tree_node const*,
tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/gcc/tree.cc:9363
0xf6e6e4 contains_struct_check(tree_node*, tree_node_structure_enum, char
const*, int, char const*)
        ../../gcc/gcc/tree.h:3892
0x138977b tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:22331
0x138b7d0 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:22733
0x137f4ce tsubst_call_args
        ../../gcc/gcc/cp/pt.cc:20788
0x1384785 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:21678
0x1036cc3 tsubst_valid_expression_requirement
        ../../gcc/gcc/cp/constraint.cc:1346
0x1036e96 tsubst_simple_requirement
        ../../gcc/gcc/cp/constraint.cc:1383
0x1037abd tsubst_requirement
        ../../gcc/gcc/cp/constraint.cc:1598
0x10381d7 tsubst_requires_expr
        ../../gcc/gcc/cp/constraint.cc:1738
0x103839d tsubst_requires_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/constraint.cc:1762
0x138b760 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:22721
0x138190e tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:21199
0x136b590 tsubst_init
        ../../gcc/gcc/cp/pt.cc:17886
0x13a12be regenerate_decl_from_template
        ../../gcc/gcc/cp/pt.cc:27695
0x13a2a63 instantiate_body
        ../../gcc/gcc/cp/pt.cc:28011
0x13a4cf2 instantiate_decl(tree_node*, bool, bool)
        ../../gcc/gcc/cp/pt.cc:28367
0x112ea72 mark_used(tree_node*, int)
        ../../gcc/gcc/cp/decl2.cc:6584
0x13429ea lookup_and_finish_template_variable(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/pt.cc:10694
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

We crash on this:

              /* This can happen for a parameter name used later in a function
                 declaration (such as in a late-specified return type).  Just
                 make a dummy decl, since it's only used for its type.  */
              gcc_assert (cp_unevaluated_operand);
              r = tsubst_decl (t, args, complain);
              /* Give it the template pattern as its context; its true context
                 hasn't been instantiated yet and this is good enough for
                 mangling.  */
              DECL_CONTEXT (r) = DECL_CONTEXT (t);

because the 'tsubst_decl' on the PARM_DECL t returns error_mark_node.

This doesn't occur without using modules, so something's gone awry. I'll need
to try and reduce at some point.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue

Reply via email to