From: Patrick Palka <patrick@parcs.ath.cx>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, Patrick Palka <patrick@parcs.ath.cx>
Subject: [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
Date: Tue, 15 Dec 2015 21:16:00 -0000 [thread overview]
Message-ID: <1450214192-23542-1-git-send-email-patrick@parcs.ath.cx> (raw)
This patch just makes convert_for_initialization() to avoid eagerly
decaying an array, function, etc if the type we're converting to is a
class type, so that the correct conversion constructor could be later be
selected in perform_implicit_conversion_flags().
Bootstrap + regtest in progress on x86_64-pc-linux-gnu, OK to commit if
no new regressions?
gcc/cp/ChangeLog:
PR c++/16333
PR c++/41426
PR c++/59878
PR c++/66895
* typeck.c (convert_for_initialization): Don't perform an early
decaying conversion if converting to a class type.
gcc/testsuite/ChangeLog:
PR c++/16333
PR c++/41426
PR c++/59878
PR c++/66895
* g++.dg/conversion/pr16333.C: New test.
* g++.dg/conversion/pr41426.C: New test.
* g++.dg/conversion/pr59878.C: New test.
* g++.dg/conversion/pr66895.C: New test.
---
gcc/cp/typeck.c | 16 +++++++++-------
gcc/testsuite/g++.dg/conversion/pr16333.C | 8 ++++++++
gcc/testsuite/g++.dg/conversion/pr41426.C | 28 ++++++++++++++++++++++++++++
gcc/testsuite/g++.dg/conversion/pr59878.C | 19 +++++++++++++++++++
gcc/testsuite/g++.dg/conversion/pr66895.C | 11 +++++++++++
5 files changed, 75 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/conversion/pr16333.C
create mode 100644 gcc/testsuite/g++.dg/conversion/pr41426.C
create mode 100644 gcc/testsuite/g++.dg/conversion/pr59878.C
create mode 100644 gcc/testsuite/g++.dg/conversion/pr66895.C
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 39c1af2..1059b26 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8479,13 +8479,15 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags,
|| (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
return error_mark_node;
- if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
- && TREE_CODE (type) != ARRAY_TYPE
- && (TREE_CODE (type) != REFERENCE_TYPE
- || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
- || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
- && !TYPE_REFFN_P (type))
- || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
+ if (MAYBE_CLASS_TYPE_P (type))
+ ;
+ else if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
+ && TREE_CODE (type) != ARRAY_TYPE
+ && (TREE_CODE (type) != REFERENCE_TYPE
+ || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
+ || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
+ && !TYPE_REFFN_P (type))
+ || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
rhs = decay_conversion (rhs, complain);
rhstype = TREE_TYPE (rhs);
diff --git a/gcc/testsuite/g++.dg/conversion/pr16333.C b/gcc/testsuite/g++.dg/conversion/pr16333.C
new file mode 100644
index 0000000..979e0ac
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr16333.C
@@ -0,0 +1,8 @@
+// PR c++/16333
+
+struct X {
+ X (const int (&)[3]);
+};
+
+int a[3];
+X foo () { return a; }
diff --git a/gcc/testsuite/g++.dg/conversion/pr41426.C b/gcc/testsuite/g++.dg/conversion/pr41426.C
new file mode 100644
index 0000000..cc86dd5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr41426.C
@@ -0,0 +1,28 @@
+// PR c++/41426
+
+template <typename _T>
+struct A
+{
+ template <int _N>
+ A(_T (&V)[_N]);
+ A();
+};
+
+A<float> g1()
+{
+ float f[] = {1.1f, 2.3f};
+ return f;
+}
+
+struct B
+{
+ B (int (&v)[10]);
+ B();
+};
+
+B g2()
+{
+ int c[10];
+ return c;
+}
+
diff --git a/gcc/testsuite/g++.dg/conversion/pr59878.C b/gcc/testsuite/g++.dg/conversion/pr59878.C
new file mode 100644
index 0000000..15f3a37
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr59878.C
@@ -0,0 +1,19 @@
+struct Test {
+ template <int N>
+ Test(const char (&array)[N]) {}
+};
+
+Test test() {
+ return "test1";
+}
+
+void test2(Test arg = "test12") {}
+
+template <typename T>
+void test3(T arg = "test123") {}
+
+int main() {
+ test();
+ test2();
+ test3<Test>();
+}
diff --git a/gcc/testsuite/g++.dg/conversion/pr66895.C b/gcc/testsuite/g++.dg/conversion/pr66895.C
new file mode 100644
index 0000000..a4bf651
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr66895.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+
+#include <cstddef>
+#include <initializer_list>
+
+struct S {
+ template<std::size_t N> S(char const (&)[N]);
+};
+struct T { S s; };
+void f(std::initializer_list<T>);
+void g() { f({{""}}); }
--
2.7.0.rc0.50.g1470d8f.dirty
next reply other threads:[~2015-12-15 21:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-15 21:16 Patrick Palka [this message]
2015-12-16 21:35 ` Jason Merrill
2015-12-16 22:10 ` Patrick Palka
2015-12-17 2:30 ` Jason Merrill
2015-12-17 10:15 ` Paolo Carlini
2015-12-17 13:27 ` Patrick Palka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1450214192-23542-1-git-send-email-patrick@parcs.ath.cx \
--to=patrick@parcs.ath.cx \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).