Boost logo

Boost :

Subject: Re: [boost] [type trait extension] I hate volatile...
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2011-07-16 05:23:11


On 16/07/11 00:22, Frédéric Bron wrote:
> I am still working on the implementation of the traits to detect operators.
> I have an issue with operators returning a volatile object (being a
> reference or not). This breaks the code I wrote to detect if the
> return type is void or not.
> In particular, the following code compiles with RET=int but not with
> RET=ret. Can somebody tell me why?
>
> It seems that any volatile object (reference or not) cannot be bound
> to a const reference apart for fundamental types. So is there any
> useful case to return a volatile object?
> If not, I can maybe just ignore those cases or it becomes to be a
> nightmare. By the way, it is 1:30am. I am going to bed!
>
> Frédéric
>
> struct ret { };
>
> #define RET int
>
> RET result;
>
> RET r() { return result; }
> RET const rc() { return result; }
> RET volatile rv() { return result; } // fails to compile
> RET const volatile rcv() { return result; } // fails to compile
> RET & rr() { return result; }
> RET const & rcr() { return result; }
> RET volatile & rvr() { return result; } // fails to compile
> RET const volatile & rcvr() { return result; } // fails to compile
>
> int main() {
> RET x;
> x=r();
> x=rc();
> x=rv(); // fails with RET=ret
> x=rcv(); // fails with RET=ret
> x=rr();
> x=rcr();
> x=rvr();
> x=rcvr();
> return 0;
> }

I think you're mis-diagnosing this error. Experiments suggest that when
RET=int the cv-qualifiers are ignored on the function return type, so
rc, rv, and rcv are all defining functions identical to r. When RET=ret
the qualifiers are not ignored.

I can't find anything in the C++0x standard (N3290) to suggest that this
should happen. The only thing I see about cv-qualifiers on return types
is footnote 98 in [dcl.fct] p3:

98) As indicated by syntax, cv-qualifiers are a signficant component in
function return types.

John Bytheway


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