Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#10439 closed Bugs (fixed)

Flyweight: now the constructor is explicit

Reported by: akim Demaille <akim.demaille@…> Owned by: Joaquín M López Muñoz
Milestone: To Be Determined Component: flyweight
Version: Boost 1.56.0 Severity: Problem
Keywords: Cc:

Description

Hi,

The following piece of code used to work fine, but with 1.56, it now fails to compile with the two major free compilers.

Thanks!

$ cat /tmp/foo.cc
#include <string>
#include <boost/flyweight.hpp>

int main()
{
  boost::flyweight<std::string> f = {};
}
$ clang++-mp-3.5 -std=c++11 -I /opt/local/include foo.cc
foo.cc:6:33: error: chosen constructor is explicit in copy-initialization
  boost::flyweight<std::string> f = {};
                                ^   ~~
/opt/local/include/boost/flyweight/flyweight.hpp:195:14: note: constructor declared here
    explicit flyweight,
             ^
/opt/local/include/boost/flyweight/detail/perfect_fwd.hpp:79:27: note: expanded from macro 'BOOST_FLYWEIGHT_PERFECT_FWD'
template<typename... Args>name(Args&&... args) \
                          ^
1 error generated.
$ g++-mp-4.9 -std=c++11 -I /opt/local/include foo.cc
foo.cc: In function 'int main()':
foo.cc:6:38: error: converting to 'boost::flyweights::flyweight<std::basic_string<char> >' from initializer list would use explicit constructor 'boost::flyweights::flyweight<T, Arg1, Arg2, Arg3, Arg4, Arg5>::flyweight(Args&& ...) [with Args = {}; T = std::basic_string<char>; Arg1 = boost::parameter::void_; Arg2 = boost::parameter::void_; Arg3 = boost::parameter::void_; Arg4 = boost::parameter::void_; Arg5 = boost::parameter::void_]'
   boost::flyweight<std::string> f = {};
                                      ^

Change History (3)

comment:1 by Akim Demaille <akim.demaille@…>, 8 years ago

The following also used to work up to 1.55, and is now broken.

$ cat foo.cc
#include <string>
#include <boost/flyweight.hpp>

using string = boost::flyweight<std::string>;

void foo(string) {}

int main()
{
  foo({});
}
$ clang++-mp-3.5 -std=c++11 -I /opt/local/include foo.cc
foo.cc:10:3: error: no matching function for call to 'foo'
  foo({});
  ^~~
foo.cc:6:6: note: candidate function not viable: cannot convert initializer list argument to 'string' (aka 'flyweight<std::string>')
void foo(string) {}
     ^
1 error generated.
$ g++-mp-4.9 -std=c++11 -I /opt/local/include foo.cc
foo.cc: In function 'int main()':
foo.cc:10:9: error: converting to 'string {aka boost::flyweights::flyweight<std::basic_string<char> >}' from initializer list would use explicit constructor 'boost::flyweights::flyweight<T, Arg1, Arg2, Arg3, Arg4, Arg5>::flyweight(Args&& ...) [with Args = {}; T = std::basic_string<char>; Arg1 = boost::parameter::void_; Arg2 = boost::parameter::void_; Arg3 = boost::parameter::void_; Arg4 = boost::parameter::void_; Arg5 = boost::parameter::void_]'
   foo({});
         ^

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

Resolution: fixed
Status: newclosed

Fixed at:

https://github.com/boostorg/flyweight/commit/20230d966942fa4bfddba3a2b8fea0cd26eee6d4

I'd appreciate if you could test the fix works for you.

comment:3 by Akim Demaille <akim.demaille@…>, 8 years ago

Hi Joaquin,

Thanks for the quick fix. Yes, I can confirm that it fixed my issue. FWIW, I have also observe a 20% speed up of my parsing routines (from 1.55 to 1.56), that use flyweight for identifiers. Nice!

Note: See TracTickets for help on using tickets.