Boost logo

Boost :

Subject: Re: [boost] [optional] optional(Expr&&) is insufficiently constrained
From: Paul Fultz II (pfultz2_at_[hidden])
Date: 2016-02-18 19:53:02


On Thursday, February 18, 2016 at 6:19:54 PM UTC-6, Andrzej Krzemienski
wrote:
>
> 2016-02-18 23:03 GMT+01:00 Stephan T. Lavavej <s..._at_[hidden]
> <javascript:>>:
>
> > Hi,
> >
> > A user reported a bug (VSO#191303/Connect#2351203, see [1]) using
> > Boost.Optional with MSVC 2015 Update 2. The original test case involved
> a
> > minor bug in VC's tuple, which I'll look into fixing in the future
> > (specifically, N-tuples recursively construct (N - 1)-tuples, in a way
> > that's visible to overload resolution). However, there is also a bug in
> > boost::optional.
> >
>
> Hi,
> I have created a ticket abut this problem:
> https://svn.boost.org/trac/boost/ticket/12002
> Frankly, I do not know how to implement it in a portable way (considering
> older compilers) without type trait boost::is_constructible. I am
> currently
> blocked on it: https://svn.boost.org/trac/boost/ticket/12003.
>
> As an aside, the "prevent_binding" stuff should probably be expressed as a
> > SFINAE constraint, not a static_assert.
> >
>
> About this remark, I am not sure. I understand that you want the
> constructors to be SFINAE-friendly, but at the same time I would loose the
> opportunity to convey a text message to the user-programmers, as to what
> the problem is. Now I do it with the static_assert.
>

You can add a message to the end of boolean clause in `enable_if` in C++11,
like this:

template<class T, class=
    std::enable_if<(boost:is_constructible<T>() && "Constructor
disabled")>::type
>
optional(T&&);

So when the compiler notes that the constructor was disabled by `enable_if`,
it will point to the boolean clause which contains your message. At least on
clang, it shows a preview of the line where the diagnostic occured, so the
message is shown as well. I don't how other compilers work.

One issue with this approach is that it requires a fairly compliant C++11
compiler(allowing literal strings in template parameters). Gcc 4.9 or
earlier
does not support this. Clang does. I don't about other compilers.

 

>
> I wish I had the feature "delete for a reason"
>
> Optional::Optional(R&&r) = delete("because it would cause...");
>

Well there is no need for another new feature, just better diagnostics from
current compilers.
 
Paul


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk