Bug 61663 (CWG976) - [DR 976] Deduction for const T& conversion functions
Summary: [DR 976] Deduction for const T& conversion functions
Status: NEW
Alias: CWG976
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 63217 107771 (view as bug list)
Depends on:
Blocks: c++-core-issues
  Show dependency treegraph
 
Reported: 2014-07-01 11:36 UTC by david.k
Modified: 2023-06-10 21:23 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.2, 4.9.1, 5.0
Last reconfirmed: 2021-08-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description david.k 2014-07-01 11:36:28 UTC
GCC 4.9.0 rejects the following code:

struct F 
{
  template<class T>
  operator const T&() { static T t; return t; }
};

int main() 
{
  F f;
  int i = f;   // error: cannot convert 'F' to 'int' in initialization
}

As explained in the defects report (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#976) this used to be invalid but after the corrections in 14.8.2.3 [temp.deduct.conv] paragraphs 1-3 the above code should compile.
Comment 1 Ville Voutilainen 2014-12-14 01:01:23 UTC
Clang also rejects the code.
Comment 2 Nick Krempel 2019-05-20 17:39:27 UTC
Clang accepts the code since at least as far back as 3.0.0.
Comment 3 Andrew Pinski 2021-12-03 02:23:08 UTC
*** Bug 63217 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2022-11-20 19:30:25 UTC
*** Bug 107771 has been marked as a duplicate of this bug. ***
Comment 5 GCC Commits 2023-06-10 21:23:07 UTC
The trunk branch has been updated by Nathan Sidwell <nathan@gcc.gnu.org>:

https://gcc.gnu.org/g:80f075b410125bddb31459428760645baba1a69f

commit r14-1689-g80f075b410125bddb31459428760645baba1a69f
Author: Nathan Sidwell <nathan@acm.org>
Date:   Sat Jun 10 12:42:17 2023 -0400

    c++: Adjust conversion deduction [PR61663][DR976]
    
    Drop the return type's reference before doing cvqual and related decays.
    
            gcc/cp/
            PR c++/61663
            * pt.cc (maybe_adjust_types_for_deduction): Implement DR976.
            gcc/testsuite/
            * g++.dg/template/pr61663.C: New.