User account creation filtered due to spam.

Bug 63437 - [4.9/5 regression][C++14] Parenthesized "movable but not copyable" object doesn't compile in return statement
Summary: [4.9/5 regression][C++14] Parenthesized "movable but not copyable" object doe...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: 4.9.2
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-02 02:25 UTC by Kohei Takahashi
Modified: 2014-10-10 20:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-10-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kohei Takahashi 2014-10-02 02:25:49 UTC
After GCC 4.9, parenthesized "movable but not copyable" object doesn't compile in return statement under C++14 mode (C++11 mode does compile).
I'm not sure that the behavior was changed in C++14 spec; Clang seems compile under both of C++11/14 mode.

example:
----
struct X // movable but not copyable
{
    X() = default;
    X(X &&) = default;

    X(const X &) = delete;
};

X non_parenthesized()
{
    X x;
    return x; // works
}

X parenthesized()
{
    X x;
    return (x); // error: use of deleted function 'X::X(const X&)'
}
----

Online compiler results:
- GCC 4.8.2
 - C++11 http://melpon.org/wandbox/permlink/lRR60fvDgKfqd0UZ
 - C++14 http://melpon.org/wandbox/permlink/BAdrBmEG3euQLnqv

- GCC 4.9.1
 - C++11 http://melpon.org/wandbox/permlink/XllfUNu0VV0mnYsu
 - C++14 http://melpon.org/wandbox/permlink/qm67F6vODyADgKvQ (fail)

- GCC 5.0 20141001
 - C++11 http://melpon.org/wandbox/permlink/21bPbcuXB7S87DUG
 - C++14 http://melpon.org/wandbox/permlink/da8AeqX7HrS17T2n (fail)

- Clang 3.5.0
 - C++11 http://melpon.org/wandbox/permlink/VqgnlKRTOBHd5IDt
 - C++14 http://melpon.org/wandbox/permlink/tAkgLiaD50nOMtEz
Comment 1 Andrew Pinski 2014-10-02 03:03:35 UTC
in C++14 (a) means the same as static_cast<typeof(a) &>(a).

So it is a reference at this point which means const & is better than &&.

Or at least that is how I understand this.  Does clang implement the C++11 () rule correctly?
Comment 2 Kohei Takahashi 2014-10-02 07:40:15 UTC
(In reply to Andrew Pinski from comment #1)
> in C++14 (a) means the same as static_cast<typeof(a) &>(a).
> 
> So it is a reference at this point which means const & is better than &&.
> 
> Or at least that is how I understand this.  Does clang implement the C++11
> () rule correctly?

n3376 12.8 [class.copy] paragraph 32 says:

    When the criteria for elision of a copy operation are met or would be met save for the fact that the source
    object is a function parameter, and the object to be copied is designated by an lvalue, overload resolution to
    select the constructor for the copy is first performed as if the object were designated by an rvalue.

And latest draft says more clearly.
https://github.com/cplusplus/draft/blob/master/source/special.tex#L3021-L3062

Therefore, I think move should be performed even if parenthesized.
Comment 3 Jonathan Wakely 2014-10-02 09:08:16 UTC
Yes, the new wording is clear that parenthesized names are OK.
Comment 4 Jason Merrill 2014-10-09 18:05:49 UTC
Author: jason
Date: Thu Oct  9 18:05:17 2014
New Revision: 216042

URL: https://gcc.gnu.org/viewcvs?rev=216042&root=gcc&view=rev
Log:
	PR c++/63437
	* cp-tree.h (REF_PARENTHESIZED_P): Also allow INDIRECT_REF.
	* semantics.c (force_paren_expr): And set it.
	* typeck.c (check_return_expr): And handle it.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/paren1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
Comment 5 Jason Merrill 2014-10-10 20:35:50 UTC
Author: jason
Date: Fri Oct 10 20:35:18 2014
New Revision: 216106

URL: https://gcc.gnu.org/viewcvs?rev=216106&root=gcc&view=rev
Log:
	PR c++/63437
	* cp-tree.h (REF_PARENTHESIZED_P): Also allow INDIRECT_REF.
	* semantics.c (force_paren_expr): And set it.
	* typeck.c (check_return_expr): And handle it.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/g++.dg/cpp1y/paren1.C
Modified:
    branches/gcc-4_9-branch/gcc/cp/ChangeLog
    branches/gcc-4_9-branch/gcc/cp/cp-tree.h
    branches/gcc-4_9-branch/gcc/cp/semantics.c
    branches/gcc-4_9-branch/gcc/cp/typeck.c
Comment 6 Jason Merrill 2014-10-10 20:38:27 UTC
Fixed.