Opened 8 years ago

Closed 8 years ago

#10778 closed Bugs (fixed)

VC14 CTP4 Atomic don't compile with boost::chrono durations which are not TriviallyCopyable

Reported by: mjklaim@… Owned by: viboes
Milestone: Boost 1.58.0 Component: chrono
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc: raad@…

Description

This complete example does not compile in VC14 CTP4:

#include <atomic>
#include <boost/chrono.hpp>

std::atomic<boost::chrono::milliseconds> ms; // error C2338: atomic<T> requires T to be trivially copyable.

Using the standard library instead works as expected:

#include <atomic>
#include <chrono>


std::atomic<std::chrono::milliseconds> ms; // no error

The compiler is correct that boost::chrono::duration is not trivially copyable (as described on cppreference.com at least) but it seems (from looking at the code) that it's mostly concept check code used in constructors definitions that trigger the problem.

Change History (6)

comment:1 by raad@…, 8 years ago

Cc: raad@… added

comment:2 by viboes, 8 years ago

The problem is at least on the default constructor.

I added the default initialization as zero, but this is not correct.

Please, could you try the following

#if  defined   BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
        BOOST_FORCEINLINE BOOST_CONSTEXPR
        duration() : rep_(duration_values<rep>::zero()) { }
#else
        duration() BOOST_NOEXCEPT = default;
#endif

You would surely need

#if  defined   BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
        duration& operator=(const duration& rhs) // = default;
        {
            if (&rhs != this) rep_= rhs.rep_;
            return *this;
        }
#else
        duration& operator=(const duration& rhs) = default;
#endif

comment:3 by mjklaim@…, 8 years ago

First: I uninstalled VC14 CTP4 and installed VS2015 Preview, which is the same compiler (certainly with some bugfixes). As expected I found the same issue.

Second: I applied your changes and now it compiles (it required both changes).

I will now re-compile my boost binaries with this change, see if there is any issue but I highly doubt it.

comment:5 by mjklaim@…, 8 years ago

I had no apparent problem with the build I was talking about so I think it works in principle, but I didn't see your patches. I can't test these patches until next week.

comment:6 by viboes, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.