aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2017-03-20 02:22:43 +0000
committerJason Merrill <jason@redhat.com>2017-03-20 02:22:43 +0000
commitef971097148e4d139240ae6ca8d16d21ea448199 (patch)
treecd05875f6b290965395cbd7d9736413cb9844941
parent3d1278331dd92f6099f6cbce35916c3ec88a2969 (diff)
PR c++/80084 - wrong C++17 decomposition by reference of parameter.
* decl.c (cp_finish_decomp): Don't pull out the DECL_INITIAL of a reference decomposition. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@246273 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp27.C26
3 files changed, 30 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a7248d93ca3..7ffd818bec6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2017-03-19 Jason Merrill <jason@redhat.com>
+ PR c++/80084 - wrong C++17 decomposition by reference of parameter.
+ * decl.c (cp_finish_decomp): Don't pull out the DECL_INITIAL of a
+ reference decomposition.
+
PR c++/80077 - error with constexpr and -fno-elide-constructors.
* constexpr.c (cxx_eval_call_expression): Set ctx->call while
expanding trivial constructor.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index bf24e8ba164..0a9256680a0 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7439,9 +7439,6 @@ cp_finish_decomp (tree decl, tree first, unsigned int count)
if (TREE_CODE (type) == REFERENCE_TYPE)
{
- /* If e is a constant reference, use the referent directly. */
- if (DECL_INITIAL (decl))
- dexp = DECL_INITIAL (decl);
dexp = convert_from_reference (dexp);
type = TREE_TYPE (type);
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp27.C b/gcc/testsuite/g++.dg/cpp1z/decomp27.C
new file mode 100644
index 00000000000..f26722a1d0a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp27.C
@@ -0,0 +1,26 @@
+// PR c++/80084
+// { dg-options -std=c++1z }
+// { dg-do run }
+
+struct A
+{
+ A() { }
+ A(const A&) { }
+};
+
+struct B
+{
+ A a;
+};
+
+void f(B b)
+{
+ auto& [a] = b;
+ if (&a != &b.a)
+ __builtin_abort();
+}
+
+int main()
+{
+ f(B());
+}