Title
Unclear rules for deduction with cv-qualification
Status
nad
Section
13.10.3.2 [temp.deduct.call]
Submitter
Steve Clamage

Created on 2013-04-26.00:00:00 last changed 127 months ago

Messages

Date: 2013-09-15.00:00:00

Rationale (September, 2013):

There are no rules that would result in deducing const char in the specified example.

Date: 2022-11-20.07:54:16
  1. Simple pointer:

  2. Template argument: const T*
    Actual argument: char*
    We deduce T to be char, and by compatibility of cv-qualifiers, this deduction works.

    Now suppose that (somehow) we deduced T to be const char. We fold the resulting const const char* into const char*, and again the deduction works. Does the standard disallow this deduction? The reason for this question is in the next example.

  3. Pointer to member:

  4. Template argument: const T A<T>::*, where A is a class template
    Actual argument: char A<const char>::*
    Compilers reject this case, because if we deduce the first T to be char, we cannot match A<T>::*. But suppose we look first at the second T, deducing it to be const char. Then we get const char A<const char>::*, which is OK. Alternatively, as in the hypothetical case in example 1, suppose we deduce the first T to be const char, again we get a match.

    Arbitrarily adding extra cv-qualifiers in looking for a match, or trying different matching orders to find one that works, seems wrong. But are these approaches disallowed?

For completeness, here is a code example:

  template <typename Q>
  struct A {
    int i;
  };

  template <typename T>
  void foo(const T A<T>::*) { }

  int main() {
    A<const int> a;
    int A<const int>::*p = &A<const int>::i;
    foo(p);  // rejected by all compilers, but why?
  }
History
Date User Action Args
2013-10-14 00:00:00adminsetmessages: + msg4712
2013-10-14 00:00:00adminsetstatus: open -> nad
2013-04-26 00:00:00admincreate