Bug 67853 - decltype of parenthesized xvalue does not correctly yield rvalue-reference
Summary: decltype of parenthesized xvalue does not correctly yield rvalue-reference
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.2.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks: decltype
  Show dependency treegraph
 
Reported: 2015-10-05 13:23 UTC by Tobias Reh
Modified: 2019-07-21 21:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-07-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Reh 2015-10-05 13:23:14 UTC
The following code snippet contains the parenthesized decltype of an xvalue:

#include <type_traits>

struct Member {};
struct A { Member x; };
A MakeA();

static_assert(std::is_same<decltype((MakeA().x)), Member&&>::value, ""); // MSVC++ 2015
//static_assert(std::is_same<decltype((MakeA().x)), Member>::value, ""); // clang, gcc

The standard says in §7.1.6.2 about decltype(e)
(4.1) [...] unparenthesized case, does not apply here
(4.2) if e is an xvalue, decltype(e) is T&&, where T is the type of e;

This means clang and gcc are not standard-conformant.
Comment 1 Daniel Krügler 2015-10-05 17:29:41 UTC
It seems as if the compiler still implements CWG 421

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#421

instead of the newer CWG 616:

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#616
Comment 2 Marek Polacek 2019-07-21 21:17:56 UTC
Fixed by r260621.
Comment 3 Marek Polacek 2019-07-21 21:20:58 UTC
Author: mpolacek
Date: Sun Jul 21 21:20:27 2019
New Revision: 273652

URL: https://gcc.gnu.org/viewcvs?rev=273652&root=gcc&view=rev
Log:
	PR c++/67853
	* g++.dg/cpp0x/decltype72.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/decltype72.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Marek Polacek 2019-07-21 21:22:46 UTC
Test added.