Bug 97430 - [10/11 Regression] internal compiler error: in verify_ctor_sanity, at cp/constexpr.c:3884
Summary: [10/11 Regression] internal compiler error: in verify_ctor_sanity, at cp/cons...
Status: RESOLVED DUPLICATE of bug 96241
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.0
: P2 normal
Target Milestone: 10.3
Assignee: Not yet assigned to anyone
URL: https://www.jfrech.com/blog/235/index...
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-10-14 23:43 UTC by Jonathan Frech
Modified: 2020-10-15 14:05 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-10-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Frech 2020-10-14 23:43:03 UTC
Possible duplicate of Bug 96241.

The following one-line source file triggers an ICE with `-std=c++17`:

int main(){[](){enum E{F};struct{E e{F};}p[1]{};return p->e;};}

% g++ -std=c++17 ice.cpp
ice.cpp: In static member function ‘static constexpr main()::<lambda()>::E main()::<lambda()>::_FUN()’:
ice.cpp:1:61:   in ‘constexpr’ expansion of ‘0->main()::<lambda()>()’
ice.cpp:1:61: internal compiler error: in verify_ctor_sanity, at cp/constexpr.c:3884
    1 | int main(){[](){enum E{F};struct{E e{F};}p[1]{};return p->e;};}
      |                                                             ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
Comment 1 Marek Polacek 2020-10-14 23:54:31 UTC
Not a dup of bug 96241, this one started with r10-6527.  Use -std=c++17.
Comment 2 Marek Polacek 2020-10-15 01:48:48 UTC
A test without a lambda that ICEs with -std=c++14 too:

enum E : int { F };
struct X {
  E e{F};
};
constexpr X x[1];

auto
foo ()
{
  return x[0].e;
}

Note that we don't ICE if the X's member is changed to E e{1};.  The difference is that for the former reduced_constant_expression_p says false (due to the CONST_DECL F), so we cxx_eval_bare_aggregate and verify_ctor_sanity in cxx_eval_constant_expression/CONSTRUCTOR.  With e{1} reduced_constant_expression_p is true and we don't call cxx_eval_bare_aggregate.
Comment 3 Marek Polacek 2020-10-15 03:04:01 UTC
And that also means that this:

enum E : int { F };
struct X {
  E e{F};
};

constexpr X x[1]{};

constexpr auto
foo ()
{
  return x[0].e;
}

constexpr auto a = foo ();

started to ICE earlier, since r10-6437.
Comment 4 Marek Polacek 2020-10-15 04:03:38 UTC
This ought to fix it, though it's completely untested:

--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3661,6 +3661,10 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
     {
       tree empty_ctor = build_constructor (init_list_type_node, NULL);
       val = digest_init (elem_type, empty_ctor, tf_warning_or_error);
+      constexpr_ctx new_ctx = *ctx;
+      new_ctx.ctor = build_constructor (elem_type, NULL);
+      new_ctx.object = NULL_TREE;
+      ctx = &new_ctx;
     }
   else
     val = build_value_init (elem_type, tf_warning_or_error);
Comment 5 Marek Polacek 2020-10-15 04:07:17 UTC
...which should also fix Bug 96241 so these in fact are duplicates.
Comment 6 Marek Polacek 2020-10-15 14:05:44 UTC
Closing as a dup.

*** This bug has been marked as a duplicate of bug 96241 ***