Bug 67853

Summary: decltype of parenthesized xvalue does not correctly yield rvalue-reference
Product: gcc Reporter: Tobias Reh <treh>
Component: c++Assignee: Marek Polacek <mpolacek>
Status: RESOLVED FIXED    
Severity: normal CC: daniel.kruegler, webrown.cpp
Priority: P3    
Version: 5.2.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2019-07-21 00:00:00
Bug Depends on:    
Bug Blocks: 54366    

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.