This failure is caused by a compiler bug, and as far as we can + tell, can't be worked around in the library, although we think + the library might be made safer with respect to this bug.
+ +Specifics: the following simple test fails when it should succeed.
+
+ #include <cassert>
+
+ int const x = 0;
+ struct A
+ {
+ A(int const& y)
+ {
+ assert(&x == &y);
+ }
+ };
+
+ int main()
+ {
+ A a(x); // direct initialization works fine
+ A b = x; // copy initialization causes x to be copied before it is bound
+ }
+
+
+ The possible safety enhancement would be to cause the constructor
+ in question to be explicit for optional<T const&>; that
+ would prevent copy initialization.
+