]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: add NRV testcase [PR58050]
authorJason Merrill <jason@redhat.com>
Tue, 6 Jun 2023 16:01:23 +0000 (12:01 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 7 Jun 2023 01:24:13 +0000 (21:24 -0400)
This was fixed in GCC 10.

PR c++/58050

gcc/testsuite/ChangeLog:

* g++.dg/opt/nrv24.C: New test.

gcc/testsuite/g++.dg/opt/nrv24.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/opt/nrv24.C b/gcc/testsuite/g++.dg/opt/nrv24.C
new file mode 100644 (file)
index 0000000..7a7a59b
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/58050
+// { dg-do link }
+
+struct B {
+  B() { }
+  B(const B&); // not defined, link error on unnecessary copy
+  ~B() { }
+};
+struct A {
+  static B make() { return B(); }
+} a;
+A *ap() { return &a; }
+int main () {
+  {B b = A::make();}
+  {B B = a.make();}
+  {B b = ap()->make();}
+  {B b = A().make();}
+}