split_nonconstant_init_1 was confused by a CONSTRUCTOR with non-aggregate
type, which (with COMPOUND_LITERAL_P set) we use in a template to represent
a braced functional cast. It seems to me that there's no good reason to do
split_nonconstant_init at all in a template.
Tested x86_64-pc-linux-gnu, applying to trunk.
gcc/cp/ChangeLog:
PR c++/97899
* typeck2.c (store_init_value): Don't split_nonconstant_init in a
template.
gcc/testsuite/ChangeLog:
PR c++/97899
* g++.dg/cpp0x/initlist-template3.C: New test.
---
gcc/cp/typeck2.c | 1 +
gcc/testsuite/g++.dg/cpp0x/initlist-template3.C | 13 +++++++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-template3.C
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 412869946a5..721987e8502 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -806,6 +806,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>**
cleanups, int flags)
the bits that are constant, and then return an expression that
will perform the dynamic initialization. */
if (value != error_mark_node
+ && !processing_template_decl
&& (TREE_SIDE_EFFECTS (value)
|| vla_type_p (type)
|| ! reduced_constant_expression_p (value)))
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-template3.C
b/gcc/testsuite/g++.dg/cpp0x/initlist-template3.C
new file mode 100644
index 00000000000..b65a8473a09
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-template3.C
@@ -0,0 +1,13 @@
+// PR c++/97899
+// { dg-do compile { target c++11 } }
+
+template <typename T = int>
+int fn()
+{
+ return 1;
+}
+
+template <typename T>
+void bar() {
+ const int i = int{fn()};
+}
base-commit: 1805dbc58bac78a823e9cff075b9dc993f29c360
--
2.18.4