Bug 87530 - copy elision in return statement doesn't check for rvalue reference to object type
Summary: copy elision in return statement doesn't check for rvalue reference to object...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2018-10-05 13:57 UTC by Barry Revzin
Modified: 2020-09-17 20:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-10-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Revzin 2018-10-05 13:57:00 UTC
Example from StackOverflow (https://stackoverflow.com/q/52662407/2069064):

struct Base { };

template<typename T>
struct A : Base
{
    A();
    A(Base&&);
};

A<int> foo()
{
    A<double> v;
    return v;
}

gcc accepts this code, invoking the A(Base&&) constructor in the return statement. But the requirement in [class.copy.elision]/3 requires the first type in the selected constructor to be an rvalue reference to the object's type, which it is not.
Comment 1 Jonathan Wakely 2018-10-08 08:56:32 UTC
Smells like a variant of PR 87150 to me, but not a regression as it's been doing the wrong thing since we started treating named lvalues as rvalues in return statements.

Marek, could you take a look please?
Comment 2 Marek Polacek 2018-10-08 21:41:39 UTC
Happy to.
Comment 3 Marek Polacek 2020-09-04 15:29:08 UTC
No longer accepted since r11-2411.  The test should probably be added.
Comment 4 GCC Commits 2020-09-17 20:14:58 UTC
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:4f0aa5b051c0d3e81478bcb495e4e072b2d9827d

commit r11-3268-g4f0aa5b051c0d3e81478bcb495e4e072b2d9827d
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Sep 17 15:31:50 2020 -0400

    c++: Add tests for fixed PRs.
    
    Bugzilla inspection turned up a bunch of old(er) PRs that have been
    fixed.  Let's include them not to regress in the future.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/87530
            PR c++/58156
            PR c++/68828
            PR c++/86002
            PR c++/91525
            PR c++/96223
            PR c++/87032
            PR c++/35098
            * g++.dg/cpp0x/move-return4.C: New test.
            * g++.dg/cpp0x/vt-58156.C: New test.
            * g++.dg/cpp2a/concepts-pr68828.C: New test.
            * g++.dg/cpp2a/concepts-pr86002.C: New test.
            * g++.dg/cpp2a/concepts-pr91525.C: New test.
            * g++.dg/cpp2a/constexpr-indeterminate1.C: New test.
            * g++.dg/cpp2a/desig17.C: New test.
            * g++.dg/ext/attrib62.C: New test.
Comment 5 Marek Polacek 2020-09-17 20:18:47 UTC
Fixed.