Skip to content

CWG2978 [temp.deduct.call] Deduction and qualification conversions with references #651

Open

Description

@t3nsor

Full name of submitter: Brian Bi

Issue description: There is implementation divergence in the treatment of the following deduction:

#include <cstddef>

template <std::size_t N>
void f(const int* const (&)[N]);

int main() {
    int* a[3];
    f(a);
}

It is not clear whether bullet 4.1 of [temp.deduct.call] allows qualification conversions.

Suggested resolution: Edit [temp.deduct.call]/4.1 as follows:

If the original P is a reference type, the deduced A (i.e., the type referred to by the reference) can be more cv-qualified a type other than the transformed A that is reference-compatible ([dcl.init.ref]) with the transformed A.

(We might not need to say "transformed", actually. As far as I can tell, when the original P is a reference type, we transform A only in the case where P is a forwarding reference, and in that case no difference in cv-qualification is possible.)

Activity

  1. eisenwave commented on Dec 25, 2024

    @eisenwave
    Member

    Note that the following code indirectly reproduces this implementation divergence, and that is how the issue was originally discovered:

    #include <span>
    
    int* pointers[3];
    std::span<const int* const> s = pointers;

    GCC accepts this, and Clang (with libstdc++) rejects it. See https://stackoverflow.com/q/79264902/5740428

    Clang fails to call this overload:

    template <size_t _ArrayExtent>
    span(const int * const (&)[_ArrayExtent])

    Any resolution should make this construction of std::span valid, in my opinion.

  2. jensmaurer commented on Dec 25, 2024

    @jensmaurer
    Member

    "reference-compatible" allows derived-to-base conversions, which we don't want here (I think).

    Maybe "... can be a type similar to the transformed A that is reference-compatible with the transformed A".

  3. jensmaurer commented on Dec 30, 2024

    @jensmaurer
    Member
  4. changed the title [-][temp.deduct.call] Deduction and qualification conversions with references[/-] [+]CWG2978 [temp.deduct.call] Deduction and qualification conversions with references[/+] on Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions