* [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
@ 2015-12-15 21:16 Patrick Palka
2015-12-16 21:35 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Patrick Palka @ 2015-12-15 21:16 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, Patrick Palka
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
2015-12-15 21:16 [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early) Patrick Palka
@ 2015-12-16 21:35 ` Jason Merrill
2015-12-16 22:10 ` Patrick Palka
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2015-12-16 21:35 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 12/15/2015 04:16 PM, Patrick Palka wrote:
> + if (MAYBE_CLASS_TYPE_P (type))
> + ;
What does this patch do with conversion to const reference to class? I
think we want to check MAYBE_CLASS_TYPE_P (non_reference (type)) here.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
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
0 siblings, 2 replies; 6+ messages in thread
From: Patrick Palka @ 2015-12-16 22:10 UTC (permalink / raw)
To: Jason Merrill; +Cc: Patrick Palka, gcc-patches
On Wed, 16 Dec 2015, Jason Merrill wrote:
> On 12/15/2015 04:16 PM, Patrick Palka wrote:
>> + if (MAYBE_CLASS_TYPE_P (type))
>> + ;
>
> What does this patch do with conversion to const reference to class? I think
> we want to check MAYBE_CLASS_TYPE_P (non_reference (type)) here.
That makes sense. Here's an updated patch using non_reference, with
tests updated to each have a reference-returning variant.
-- 8< --
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 | 10 ++++++++
gcc/testsuite/g++.dg/conversion/pr41426.C | 40 +++++++++++++++++++++++++++++++
gcc/testsuite/g++.dg/conversion/pr59878.C | 25 +++++++++++++++++++
gcc/testsuite/g++.dg/conversion/pr66895.C | 16 +++++++++++++
5 files changed, 100 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..a06ecf0 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 (non_reference (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..810c12a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr16333.C
@@ -0,0 +1,10 @@
+// PR c++/16333
+
+struct X {
+ X (const int (&)[3]);
+};
+
+int a[3];
+X foo1 () { return a; }
+const X &foo2 () { return a; } // { dg-warning "returning reference to temporary" }
+X &foo3 () { return a; } // { dg-error "invalid initialization" }
diff --git a/gcc/testsuite/g++.dg/conversion/pr41426.C b/gcc/testsuite/g++.dg/conversion/pr41426.C
new file mode 100644
index 0000000..78ec5fb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr41426.C
@@ -0,0 +1,40 @@
+// 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;
+}
+
+const A<float> &g3()
+{
+ float f[] = {1.1f, 2.3f};
+ return f; // { dg-warning "returning reference to temporary" }
+}
+
+A<float> &g4()
+{
+ float f[] = {1.1f, 2.3f};
+ return f; // { dg-error "invalid initialization" }
+}
+
+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..ed567fe
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr59878.C
@@ -0,0 +1,25 @@
+// PR c++/59878
+
+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") {}
+
+template <typename T>
+void test4(const T &arg = "test123") {}
+
+int main() {
+ test();
+ test2();
+ test3<Test>();
+ test4<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..14203bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr66895.C
@@ -0,0 +1,16 @@
+// PR c++/66895
+// { dg-do compile { target c++11 } }
+
+#include <cstddef>
+#include <initializer_list>
+
+struct S {
+ template<std::size_t N> S(char const (&)[N]);
+};
+struct T1 { S s; };
+void f1(std::initializer_list<T1>);
+void g1() { f1({{""}}); }
+
+struct T2 { const S& s; };
+void f2(std::initializer_list<T2>);
+void g2() { f2({{""}}); }
--
2.7.0.rc0.50.g1470d8f.dirty
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
2015-12-16 22:10 ` Patrick Palka
@ 2015-12-17 2:30 ` Jason Merrill
2015-12-17 10:15 ` Paolo Carlini
1 sibling, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2015-12-17 2:30 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches
OK, thanks.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
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
1 sibling, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2015-12-17 10:15 UTC (permalink / raw)
To: Patrick Palka, Jason Merrill; +Cc: gcc-patches
Hi,
On 16/12/2015 23:10, Patrick Palka wrote:
> gcc/cp/ChangeLog:
>
> PR c++/59878
> * typeck.c (convert_for_initialization): Don't perform an early
> decaying conversion if converting to a class type.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/59878
> * g++.dg/conversion/pr59878.C: New test.
Nit: note that the actual bug number is 59879, not 59878. Can you please
correct all those 8 to 9?
Thanks a lot!
Paolo.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early)
2015-12-17 10:15 ` Paolo Carlini
@ 2015-12-17 13:27 ` Patrick Palka
0 siblings, 0 replies; 6+ messages in thread
From: Patrick Palka @ 2015-12-17 13:27 UTC (permalink / raw)
To: Paolo Carlini; +Cc: Patrick Palka, Jason Merrill, gcc-patches
On Thu, 17 Dec 2015, Paolo Carlini wrote:
> Hi,
>
> On 16/12/2015 23:10, Patrick Palka wrote:
>> gcc/cp/ChangeLog:
>>
>> PR c++/59878
>> * typeck.c (convert_for_initialization): Don't perform an early
>> decaying conversion if converting to a class type.
>>
>> gcc/testsuite/ChangeLog:
>>
>> PR c++/59878
>> * g++.dg/conversion/pr59878.C: New test.
> Nit: note that the actual bug number is 59879, not 59878. Can you please
> correct all those 8 to 9?
Sorry about that... Going to correct this with the following patch after
a quick regtest:
--- 8< ---
Subject: [PATCH] Fix wrong PR references
PR c++/59878 -> PR c++/59879
---
gcc/cp/ChangeLog | 2 +-
gcc/testsuite/ChangeLog | 4 ++--
gcc/testsuite/g++.dg/conversion/pr59878.C | 25 -------------------------
gcc/testsuite/g++.dg/conversion/pr59879.C | 25 +++++++++++++++++++++++++
4 files changed, 28 insertions(+), 28 deletions(-)
delete mode 100644 gcc/testsuite/g++.dg/conversion/pr59878.C
create mode 100644 gcc/testsuite/g++.dg/conversion/pr59879.C
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 14292e9..a192f00 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -2,7 +2,7 @@
PR c++/16333
PR c++/41426
- PR c++/59878
+ PR c++/59879
PR c++/66895
* typeck.c (convert_for_initialization): Don't perform an early
decaying conversion if converting to a class type.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fafa8cc..7386f6b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -37,11 +37,11 @@
PR c++/16333
PR c++/41426
- PR c++/59878
+ PR c++/59879
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/pr59879.C: New test.
* g++.dg/conversion/pr66895.C: New test.
2015-12-16 Martin Sebor <msebor@redhat.com>
diff --git a/gcc/testsuite/g++.dg/conversion/pr59878.C b/gcc/testsuite/g++.dg/conversion/pr59878.C
deleted file mode 100644
index ed567fe..0000000
--- a/gcc/testsuite/g++.dg/conversion/pr59878.C
+++ /dev/null
@@ -1,25 +0,0 @@
-// PR c++/59878
-
-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") {}
-
-template <typename T>
-void test4(const T &arg = "test123") {}
-
-int main() {
- test();
- test2();
- test3<Test>();
- test4<Test>();
-}
diff --git a/gcc/testsuite/g++.dg/conversion/pr59879.C b/gcc/testsuite/g++.dg/conversion/pr59879.C
new file mode 100644
index 0000000..7bd5b99
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr59879.C
@@ -0,0 +1,25 @@
+// PR c++/59879
+
+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") {}
+
+template <typename T>
+void test4(const T &arg = "test123") {}
+
+int main() {
+ test();
+ test2();
+ test3<Test>();
+ test4<Test>();
+}
--
2.7.0.rc0.50.g1470d8f.dirty
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-12-17 13:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-15 21:16 [PATCH] Fix some blockers of PR c++/24666 (arrays decay to pointers too early) Patrick Palka
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
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).