aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-04-12 13:24:44 -0400
committerJason Merrill <jason@redhat.com>2024-04-12 15:34:29 -0400
commitd435571b54b02946c97b5b24f20e5a7058fd96a1 (patch)
treedcefab193f8f1cc586c1722e3dc0757f5c899e3b /gcc/testsuite/g++.dg/cpp0x
parentc9500083073ff5e0f5c1c9db92d7ce6e51a62919 (diff)
downloadgcc-d435571b54b02946c97b5b24f20e5a7058fd96a1.zip
gcc-d435571b54b02946c97b5b24f20e5a7058fd96a1.tar.gz
gcc-d435571b54b02946c97b5b24f20e5a7058fd96a1.tar.bz2
c++: reference list-init, conversion fn [PR113141]
The original testcase in PR113141 is an instance of CWG1996; the standard fails to consider conversion functions when initializing a reference directly from an initializer-list of one element, but then does consider them when initializing a temporary. I have a proposed fix for this defect, which is implemented here. DR 1996 PR c++/113141 gcc/cp/ChangeLog: * call.cc (reference_binding): Check direct binding from a single-element list. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-ref1.C: New test. * g++.dg/cpp0x/initlist-ref2.C: New test. * g++.dg/cpp0x/initlist-ref3.C: New test. Co-authored-by: Patrick Palka <ppalka@redhat.com>
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x')
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist-ref1.C16
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist-ref2.C10
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist-ref3.C13
3 files changed, 39 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-ref1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-ref1.C
new file mode 100644
index 0000000..f893f12
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-ref1.C
@@ -0,0 +1,16 @@
+// PR c++/113141
+// { dg-do compile { target c++11 } }
+
+struct ConvToRef {
+ operator int&();
+};
+
+struct A { int& r; };
+
+void f(A);
+
+int main() {
+ ConvToRef c;
+ A a{{c}};
+ f({{c}});
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-ref2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-ref2.C
new file mode 100644
index 0000000..401d868
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-ref2.C
@@ -0,0 +1,10 @@
+// CWG1996
+// { dg-do compile { target c++11 } }
+
+struct S { operator struct D &(); } s;
+D &d{s}; // OK, direct binding
+
+namespace N1 {
+ struct S { operator volatile struct D &(); } s;
+ const D &dr{s}; // { dg-error "invalid user-defined|discards qualifiers" }
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-ref3.C b/gcc/testsuite/g++.dg/cpp0x/initlist-ref3.C
new file mode 100644
index 0000000..e2cc1de
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-ref3.C
@@ -0,0 +1,13 @@
+// CWG1996
+// { dg-do compile { target c++11 } }
+
+struct D { constexpr D() {} } d;
+struct S {
+ template <class T>
+ constexpr operator T& () const { return d; }
+};
+constexpr S s;
+constexpr const D &dr1(s);
+static_assert (&dr1 == &d, "");
+constexpr const D &dr2{s};
+static_assert (&dr2 == &d, "");