aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2019-02-20 10:47:02 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2019-02-20 10:47:02 +0000
commit9ccdc43d5ee4a3ecdccc10c9d28fc90db6d13eb3 (patch)
tree2b881c9ce3df628ba11469416bb0ea510161e96c /gcc
parent54603edcb1a82307fa28a54ade7d978db7599180 (diff)
downloadgcc-9ccdc43d5ee4a3ecdccc10c9d28fc90db6d13eb3.zip
gcc-9ccdc43d5ee4a3ecdccc10c9d28fc90db6d13eb3.tar.gz
gcc-9ccdc43d5ee4a3ecdccc10c9d28fc90db6d13eb3.tar.bz2
re PR c++/84536 (ICE with non-type template parameter)
/cp 2019-02-20 Paolo Carlini <paolo.carlini@oracle.com> PR c++/84536 * pt.c (tsubst_init): Diagnose an initializer expanding to an empty list of expressions; tweak wrt dependent types. (regenerate_decl_from_template): For VAR_DECLs call tsubst_init instead of tsubst_expr. /testsuite 2019-02-20 Paolo Carlini <paolo.carlini@oracle.com> PR c++/84536 * g++.dg/cpp1y/var-templ60.C: New. From-SVN: r269037
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/pt.c49
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/var-templ60.C9
4 files changed, 53 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3fe0ced..bdbbf84 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2019-02-20 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/84536
+ * pt.c (tsubst_init): Diagnose an initializer expanding to an
+ empty list of expressions; tweak wrt dependent types.
+ (regenerate_decl_from_template): For VAR_DECLs call tsubst_init
+ instead of tsubst_expr.
+
2019-02-19 Jason Merrill <jason@redhat.com>
PR c++/88368 - wrong 'use of deleted function'
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a69a17a..8c5a1b3 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -15422,21 +15422,35 @@ tsubst_init (tree init, tree decl, tree args,
init = tsubst_expr (init, args, complain, in_decl, false);
- if (!init && TREE_TYPE (decl) != error_mark_node)
- {
- /* If we had an initializer but it
- instantiated to nothing,
- value-initialize the object. This will
- only occur when the initializer was a
- pack expansion where the parameter packs
- used in that expansion were of length
- zero. */
- init = build_value_init (TREE_TYPE (decl),
- complain);
- if (TREE_CODE (init) == AGGR_INIT_EXPR)
- init = get_target_expr_sfinae (init, complain);
- if (TREE_CODE (init) == TARGET_EXPR)
- TARGET_EXPR_DIRECT_INIT_P (init) = true;
+ tree type = TREE_TYPE (decl);
+
+ if (!init && type != error_mark_node)
+ {
+ if (tree auto_node = type_uses_auto (type))
+ {
+ if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
+ {
+ if (complain & tf_error)
+ error ("initializer for %q#D expands to an empty list "
+ "of expressions", decl);
+ return error_mark_node;
+ }
+ }
+ else if (!dependent_type_p (type))
+ {
+ /* If we had an initializer but it
+ instantiated to nothing,
+ value-initialize the object. This will
+ only occur when the initializer was a
+ pack expansion where the parameter packs
+ used in that expansion were of length
+ zero. */
+ init = build_value_init (type, complain);
+ if (TREE_CODE (init) == AGGR_INIT_EXPR)
+ init = get_target_expr_sfinae (init, complain);
+ if (TREE_CODE (init) == TARGET_EXPR)
+ TARGET_EXPR_DIRECT_INIT_P (init) = true;
+ }
}
return init;
@@ -24053,9 +24067,8 @@ regenerate_decl_from_template (tree decl, tree tmpl, tree args)
{
start_lambda_scope (decl);
DECL_INITIAL (decl) =
- tsubst_expr (DECL_INITIAL (code_pattern), args,
- tf_error, DECL_TI_TEMPLATE (decl),
- /*integral_constant_expression_p=*/false);
+ tsubst_init (DECL_INITIAL (code_pattern), decl, args,
+ tf_error, DECL_TI_TEMPLATE (decl));
finish_lambda_scope ();
if (VAR_HAD_UNKNOWN_BOUND (decl))
TREE_TYPE (decl) = tsubst (TREE_TYPE (code_pattern), args,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 231a6f3..cd45bc5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-20 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/84536
+ * g++.dg/cpp1y/var-templ60.C: New.
+
2019-02-20 Li Jia He <helijia@linux.ibm.com>
PR target/88100
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ60.C b/gcc/testsuite/g++.dg/cpp1y/var-templ60.C
new file mode 100644
index 0000000..029e65a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ60.C
@@ -0,0 +1,9 @@
+// PR c++/84536
+// { dg-do compile { target c++14 } }
+
+template<int... N> auto foo(N...); // { dg-error "initializer" }
+
+void bar()
+{
+ foo<>();
+}