aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-08-08 10:32:51 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-08-08 10:32:51 +0200
commit5e539332c47faa6d6df728d27fae5d02805ca5ec (patch)
treec447858039f5c99a47d3870bbeec66f9fafc4ca1
parentbf533db8059e25668db76845390786e7fa5f3a76 (diff)
downloadgcc-5e539332c47faa6d6df728d27fae5d02805ca5ec.zip
gcc-5e539332c47faa6d6df728d27fae5d02805ca5ec.tar.gz
gcc-5e539332c47faa6d6df728d27fae5d02805ca5ec.tar.bz2
re PR c++/86836 (internal compiler error on structured bindings with shadow parameter on templated function)
PR c++/86836 * pt.c (tsubst_expr): For structured bindings, call tsubst_decomp_names before tsubst_init, not after it. * g++.dg/cpp1z/decomp46.C: New test. From-SVN: r263391
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/pt.c35
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp46.C25
4 files changed, 50 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ed3ad71..a6bdc04 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2018-08-08 Jakub Jelinek <jakub@redhat.com>
+ PR c++/86836
+ * pt.c (tsubst_expr): For structured bindings, call tsubst_decomp_names
+ before tsubst_init, not after it.
+
PR c++/86738
* constexpr.c (cxx_eval_binary_expression): For arithmetics involving
NULL pointer set *non_constant_p to true.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2780504..0a5d112 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16740,7 +16740,17 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
else
{
int const_init = false;
+ unsigned int cnt = 0;
+ tree first = NULL_TREE, ndecl = error_mark_node;
maybe_push_decl (decl);
+
+ if (VAR_P (decl)
+ && DECL_DECOMPOSITION_P (decl)
+ && TREE_TYPE (pattern_decl) != error_mark_node)
+ ndecl = tsubst_decomp_names (decl, pattern_decl, args,
+ complain, in_decl, &first,
+ &cnt);
+
if (VAR_P (decl)
&& DECL_PRETTY_FUNCTION_P (decl))
{
@@ -16756,23 +16766,14 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
if (VAR_P (decl))
const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P
(pattern_decl));
- if (VAR_P (decl)
- && DECL_DECOMPOSITION_P (decl)
- && TREE_TYPE (pattern_decl) != error_mark_node)
- {
- unsigned int cnt;
- tree first;
- tree ndecl
- = tsubst_decomp_names (decl, pattern_decl, args,
- complain, in_decl, &first, &cnt);
- if (ndecl != error_mark_node)
- cp_maybe_mangle_decomp (ndecl, first, cnt);
- cp_finish_decl (decl, init, const_init, NULL_TREE, 0);
- if (ndecl != error_mark_node)
- cp_finish_decomp (ndecl, first, cnt);
- }
- else
- cp_finish_decl (decl, init, const_init, NULL_TREE, 0);
+
+ if (ndecl != error_mark_node)
+ cp_maybe_mangle_decomp (ndecl, first, cnt);
+
+ cp_finish_decl (decl, init, const_init, NULL_TREE, 0);
+
+ if (ndecl != error_mark_node)
+ cp_finish_decomp (ndecl, first, cnt);
}
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6eb02bb..e614fed 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2018-08-08 Jakub Jelinek <jakub@redhat.com>
+ PR c++/86836
+ * g++.dg/cpp1z/decomp46.C: New test.
+
PR c++/86738
* g++.dg/opt/pr86738.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp46.C b/gcc/testsuite/g++.dg/cpp1z/decomp46.C
new file mode 100644
index 0000000..e159b6a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp46.C
@@ -0,0 +1,25 @@
+// PR c++/86836
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A {
+ int operator*();
+ void operator++();
+ bool operator!=(A);
+};
+template <typename> class map {
+public:
+ A begin();
+ A end();
+};
+
+template <typename T> void mergemap(map<T> orig, map<T> toadd) {
+ for (auto p : toadd)
+ auto [orig] = orig; // { dg-error "use of 'orig' before deduction of 'auto'" }
+} // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
+
+int
+main() {
+ map<double> x, y;
+ mergemap(x, y);
+}