cplusplus / cplusplus/draft

[temp.deduct.conv] Implementations think there is a defect in this subclause

Open
#5,123 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

cwg
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

#include <iostream>
struct C{
    template<typename Type>
    operator Type(){
        Type a{};
        return a;
    }
};

int main(){
    int const& rf = C{};
}

Consider the above example, the rules about deducing conversion function template arguments in defined as
[temp.deduct.conv] p1

Template argument deduction is done by comparing the return type of the conversion function template (call it P) with the type specified by the conversion-type-id of the conversion-function-id being looked up (call it A) as described in [temp.deduct.type]. If the conversion-function-id is constructed during overload resolution ([over.match.funcs]), the following transformations apply.

Implementations give the deduced A with the type int. However, according to [temp.deduct.conv] p1, [temp.deduct.conv] p2, [temp.deduct.conv] p3, and [temp.deduct.conv] p4, the deduced A should be int const. Since [temp.deduct.conv] p4 remove the top-level cv-qualifier prior to remove the reference. For this divergence, Clang's sources give the interpretation, which says

If A is a reference type, the type referred to by A is used for type deduction. We work around a defect in the standard here: cv-qualifiers are also removed from P and A in this case, unless P was a reference type.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with [temp.deduct.conv] paragraphs 1–4 and compare their deduction order with the Godbolt example linked in the issue. Read the referenced Clang logic in clang/lib/Sema/SemaTemplateDeduction.cpp around lines 4430–4437. Done means reaching an agreed resolution for the discrepancy and, if necessary, clarifying the draft wording.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.