Created on 2013-04-26.00:00:00 last changed 135 months ago
Rationale (September, 2013):
There are no rules that would result in deducing const char in the specified example.
Simple pointer:
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.
Pointer to member:
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:00 | admin | set | messages: + msg4712 |
2013-10-14 00:00:00 | admin | set | status: open -> nad |
2013-04-26 00:00:00 | admin | create |