- Title
- Explicit conversion functions in direct class initialization
- Status
- cd2
- Section
- 12.2.2.5 [over.match.copy]
- Submitter
- Jason Merrill
Created on 2009-05-13.00:00:00 last changed 199 months ago
Messages
Date: 2010-03-15.00:00:00
[Voted into WP at March, 2010 meeting.]
Date: 2009-10-15.00:00:00
Proposed resolution (October, 2009): Change 12.2.2.5 [over.match.copy] paragraph 1 second bullet
as follows:
Date: 2009-05-13.00:00:00
Consider the following example: It's clear that the B constructor and the declaration of
j are well-formed and the declarations of i and
c are ill-formed. But what about the declaration of c2 ?
This is supposed to work, but it doesn't under the current wording.
C c2(a) is direct-initialization of a class, so
constructors are considered. The only possible candidate is the
default copy constructor. So we look for a conversion from A
to const C& . There is a conversion operator to
C , but it is explicit and we are now performing
copy-initialization of a reference temporary, so it is not a
candidate, and the declaration of c2 is ill-formed.
struct C { };
struct A {
explicit operator int() const;
explicit operator C() const;
};
struct B {
int i;
B(const A& a): i(a) { }
};
int main() {
A a;
int i = a;
int j(a);
C c = a;
C c2(a);
}
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2010-03-29 00:00:00 | admin | set | messages: + msg2724 |
| 2010-03-29 00:00:00 | admin | set | status: ready -> cd2 |
| 2009-11-08 00:00:00 | admin | set | messages: + msg2369 |
| 2009-11-08 00:00:00 | admin | set | status: open -> ready |
| 2009-05-13 00:00:00 | admin | create | |