Here during ahead of time checking of C{}, we indirectly call get_nsdmi
for C::m from finish_compound_literal, which in turn calls
break_out_target_exprs for C::m's (non-templated) initializer, during
which we end up building a call to A::~A and checking expr_noexcept_p
for it (from build_vec_delete_1).  But this is all done with
processing_template_decl set, so the built A::~A call is templated
(whose form r12-6897-gdec8d0e5fa00ceb2 recently changed) which
expr_noexcept_p doesn't expect and we crash.

In r10-6183-g20afdcd3698275 we fixed a similar issue by guarding a
expr_noexcept_p call with !processing_template_decl, which works here
too.  But it seems to me since the initializer we obtain in get_nsdmi is
always non-templated, it should be calling break_out_target_exprs with
processing_template_decl cleared since otherwise the function might end
up mixing templated and non-templated trees.

I'm not sure about this though, perhaps this is not the best fix here.
Alternatively, when processing_template_decl we could make get_nsdmi
avoid calling break_out_target_exprs at all or something.  Additionally,
perhaps break_out_target_exprs should be a no-op more generally when
processing_template_decl since we shouldn't see any TARGET_EXPRs inside
a template?

Bootstrapped and regtested on x86_64-pc-linux-gnu.

        PR c++/108116

gcc/cp/ChangeLog:

        * init.cc (get_nsdmi): Clear processing_template_decl before
        processing the non-templated initializer.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp0x/nsdmi-template24.C: New test.
---
 gcc/cp/init.cc                                |  8 ++++++-
 gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C | 22 +++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 73e6547c076..c4345ebdaea 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -561,7 +561,8 @@ perform_target_ctor (tree init)
   return init;
 }
 
-/* Return the non-static data initializer for FIELD_DECL MEMBER.  */
+/* Return the non-static data initializer for FIELD_DECL MEMBER.
+   The initializer returned is always non-templated.  */
 
 static GTY((cache)) decl_tree_cache_map *nsdmi_inst;
 
@@ -670,6 +671,11 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t 
complain)
       current_class_ptr = build_address (current_class_ref);
     }
 
+  /* Since INIT is always non-templated clear processing_template_decl
+     before processing it so that we don't interleave templated and
+     non-templated trees.  */
+  processing_template_decl_sentinel ptds;
+
   /* Strip redundant TARGET_EXPR so we don't need to remap it, and
      so the aggregate init code below will see a CONSTRUCTOR.  */
   bool simple_target = (init && SIMPLE_TARGET_EXPR_P (init));
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C 
b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C
new file mode 100644
index 00000000000..202c67d7321
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template24.C
@@ -0,0 +1,22 @@
+// PR c++/108116
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+struct A {
+  A(int);
+  ~A();
+};
+
+struct B {
+  B(std::initializer_list<A>);
+};
+
+struct C {
+  B m{0};
+};
+
+template<class>
+void f() {
+  C c = C{};
+};
-- 
2.39.0.95.g7c2ef319c5

Reply via email to