Opened 8 years ago

Closed 8 years ago

#10844 closed Bugs (fixed)

flyweight: multiple default constructors with real perfect forwarding

Reported by: tore.halvorsen@… Owned by: Joaquín M López Muñoz
Milestone: To Be Determined Component: flyweight
Version: Boost 1.57.0 Severity: Cosmetic
Keywords: Cc:

Description

Flyweight gets two default constructors, since it has a direct default constructor

flyweight():h(core::insert()){}

and one based on variable template arguments, which can be zero.

#define BOOST_FLYWEIGHT_PERFECT_FWD_CTR_BODY(args) \
  :h(core::insert(BOOST_FLYWEIGHT_FORWARD(args))){}

  BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(
    explicit flyweight,
    BOOST_FLYWEIGHT_PERFECT_FWD_CTR_BODY)

#undef BOOST_FLYWEIGHT_PERFECT_FWD_CTR_BODY

which can expand to:

template<typename... Args>
explicit flyweight(Args&&... args) 
:h(core::insert(std::forward<Args>(args)...)){}

Change History (9)

comment:1 by Joaquín M López Muñoz, 8 years ago

As far as I understand C++ rules, this should not raise any kind of ambiguity as the default ctor should be preferred over the templated ctor (called with no args). Are you having warnings with some compiler?

in reply to:  1 comment:2 by tore.halvorsen@…, 8 years ago

Replying to joaquin:

As far as I understand C++ rules, this should not raise any kind of ambiguity as the default ctor should be preferred over the templated ctor (called with no args). Are you having warnings with some compiler?

I get warnings from MS Visual Studio 2013.

You are probably right in that the default ctor is preferred. It's probably just a cosmetic warning.

comment:3 by Joaquín M López Muñoz, 8 years ago

OK, I'll fix it then tonight if I have a moment to spare. Can I count on your support to verify that the warning goes away after I do the commit?

in reply to:  3 comment:4 by tore.halvorsen@…, 8 years ago

Replying to joaquin:

OK, I'll fix it then tonight if I have a moment to spare. Can I count on your support to verify that the warning goes away after I do the commit?

Sure :)

comment:5 by Joaquín M López Muñoz, 8 years ago

Here you are:

https://github.com/boostorg/flyweight/commit/8f5bbd5d57780fd33e3b527a3d406e14a4d0fd9d

Could you please report back if the warning is gone?

comment:6 by Joaquín M López Muñoz, 8 years ago

I've decided to revert the previous fix as it changes (theoretically at least) boost::flyweight public interface, and used #pragma warning(disable:4520) instead:

https://github.com/boostorg/flyweight/commit/095dcfb812ab8670af70912419e129d9ad656927

Can you check this works also? Thank you.

comment:7 by tore.halvorsen@…, 8 years ago

The first worked - I'll check the second :)

comment:8 by tore.halvorsen@…, 8 years ago

The pragma works as well.

comment:9 by Joaquín M López Muñoz, 8 years ago

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