Boost logo

Boost :

Subject: Re: [boost] Is this a MSVC bug?
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2014-05-06 14:52:23


On Tue, May 6, 2014 at 4:45 AM, Andrzej Krzemienski <akrzemi1_at_[hidden]>wrote:

> Hi,
> While tracking test failures in Boost.Optional library I discovered that
> the following program fires an assert in MS VC++ compiler (v. 10.0, 11.0,
> 12.0):
>
> #include <cassert>
>
> const int global_i = 0;
>
> struct TestingReferenceBinding
> {
> void operator=(const int& ii)
> {
> assert(&ii == &global_i);
> }
>
> void operator=(int&&) { }
> };
>
> int main()
> {
> TestingReferenceBinding ttt;
> ttt = global_i;
> }
>
> Do you know if this a bug in VC++, or if that is supposed to be valid?
>

I think MSVC is at fault. I'm curious -- what if you explicitly declare it
static? What if you make it extern and const but define it in the same
translation unit? What if you use a const type that isn't integral (I.E. a
float)? IIRC, I think this type of behavior is allowed with static const
integral data-members when initialized inline, but is illegal for
non-member consts, though I don't have the standard in front of me. It
sounds like they might just be treating static global integral constants
the same way.

-- 
-Matt Calabrese

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