Giter Site home page Giter Site logo

function's People

Contributors

anadon avatar apolukhin avatar belcourt avatar beman avatar brianweed avatar dabrahams avatar danielae avatar danieljames avatar douggregor avatar eldiener avatar glenfe avatar grafikrobot avatar hkaiser avatar imikejackson avatar jeking3 avatar jewillco avatar jngrad avatar jzmaddock avatar kojoley avatar lastique avatar marcelraad avatar mclow avatar pdimov avatar podusowski avatar romain-geissler-1a avatar steveire avatar straszheim avatar swatanabe avatar thwitt avatar vprus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

function's Issues

Compulsory use of reference for function from boost::factory

Hi,

I am migrating my code from an older Boost version to a newer, and am encountering a problem with the following code snippet (simplified for the purpose of this demo).

Here's a snippet for this purpose:

#include <boost/function.hpp>
#include <boost/functional/factory.hpp>

struct MyClass {
};

struct MyCallback {
   MyCallback(int z, int y) {}
   MyCallback(MyClass* obj1) {}
};

int main()
{
   boost::function<void(MyClass*&)>::function(boost::factory<MyCallback*>());

   auto c = boost::factory<MyCallback*>();
   boost::function<void(int&, int&)>::function(c);

   return 0;
}

This shows two ways of implementing this, using objects and simple types.

This code compiles, because there are references everywhere in the function signatures.

However, the issue comes if I change the signature like this:
boost::function<void(MyClass*)>::function(boost::factory<MyCallback*>());

boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(158): error C2664: 'MyCallback *boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>::operator ()(void) const' : cannot convert argument 1 from 'MyClass *' to 'MyClass *&'

boost::function<void(int, int&)>::function(c);

boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(158): error C2664: 'MyCallback *boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>::operator ()(void) const' : cannot convert argument 1 from 'int' to 'int &'

The function template seems to require for every parameter in the function signature a reference, and no longer takes a simple parameter nor a pointer parameter.

After investigating quite a bit, it seems to come from function_template.hpp:32
# define BOOST_FUNCTION_ARG(J,I,D) static_cast<BOOST_PP_CAT(T,I)&&>(BOOST_PP_CAT(a,I))
It looks like the static_cast<&&> is forcing the reference and not letting anything else through.
The previous correction using boost::forward didn't work either.

GCC on this matter gives the following error:

function_template.hpp:158:37: error: cannot bind non-const lvalue reference of type 'MyClass*&' to an rvalue of type 'MyClass*'

But I don't quite see how MyClass* is treated as a rvalue here...

There's also a BOOST_NO_CXX11_RVALUE_REFERENCES macro definition that'd circumvent the problem. But what's the link between Rvalue Reference allowance and forbidding any simple type & pointers?

For further reference, here's the full compiler (MSVC12 2013) error output:

boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(158): error C2664: 'MyCallback *boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>::operator ()(void) const' : cannot convert argument 1 from 'MyClass *' to 'MyClass *&'
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(152) : while compiling class template member function 'void boost::detail::function::void_function_obj_invoker1<FunctionObj,R,T0>::invoke(boost::detail::function::function_buffer &,T0)'
with
[
FunctionObj=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
, R=void
, T0=MyClass *
]
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(931) : see reference to function template instantiation 'void boost::detail::function::void_function_obj_invoker1<FunctionObj,R,T0>::invoke(boost::detail::function::function_buffer &,T0)' being compiled
with
[
FunctionObj=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
, R=void
, T0=MyClass *
]
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(931) : see reference to class template instantiation 'boost::detail::function::void_function_obj_invoker1<FunctionObj,R,T0>' being compiled
with
[
FunctionObj=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
, R=void
, T0=MyClass *
]
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(720) : see reference to function template instantiation 'void boost::function1<R,T0>::assign_to(Functor)' being compiled
with
[
R=void
, T0=MyClass *
, Functor=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
]
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(720) : see reference to function template instantiation 'void boost::function1<R,T0>::assign_to(Functor)' being compiled
with
[
R=void
, T0=MyClass *
, Functor=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
]
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(1069) : see reference to function template instantiation 'boost::function1<R,T0>::function1<boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>>(Functor,int)' being compiled
with
[
R=void
, T0=MyClass *
, Functor=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
]
boost-1.70.0\include\boost-1_70\boost\function\function_template.hpp(1069) : see reference to function template instantiation 'boost::function1<R,T0>::function1<boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>>(Functor,int)' being compiled
with
[
R=void
, T0=MyClass *
, Functor=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
]
testcpp11\consoleapplication1\consoleapplication1.cpp(62) : see reference to function template instantiation 'boost::function<void (MyClass *)>::function<boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>>(Functor,int)' being compiled
with
[
Functor=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
]
testcpp11\consoleapplication1\consoleapplication1.cpp(62) : see reference to function template instantiation 'boost::function<void (MyClass *)>::function<boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>>(Functor,int)' being compiled
with
[
Functor=boost::factory<MyCallback *,void,factory_alloc_for_pointee_and_deleter>
]

Upgrade to 1.85 causes arg1_type to be missing

When compiling the following snippet with older Boost versions, everything is OK:

#include <boost/function.hpp>

using ArgType = typename boost::function<int(int)>::arg1_type;

However with Boost 1.85 it yields an error

/scratch/apel/new_arch/develop/src/ooa/main_support/test.cpp:7:53: error: ‘arg1_type’ in ‘class boost::function<int(int)>’ does not name a type
    7 | using ArgType = typename boost::function<int(int)>::arg1_type;

The same applies for the other arguments, if the prototype has multiple arguments. From my understanding this is a regression.

Coverity static analysis defects (Trac ticket #13331)

(copied from https://svn.boost.org/trac10/ticket/13331, only Function's parts from the attached report)

Boost 1.57.0

A static analysis tool called Coverity found medium and high defects in the boost source code. See attached file for defect type, defect category, filename and line number of defect.

Defect Type Defect Category Line Number Filename
Same on both sides Incorrect expression 939 /boost/include/boost/function/function_template.hpp

GCC 12 emits `-Wuninitialized` warnings

The GCC -Wmaybe-uninitialized warning reported in #27 was silenced by a diagnostic pragma in #38, however in GCC 12 the warning has become -Wuninitialized. Reproducible on Fedora with gcc-c++-12.0.1-0.16.fc36 and gcc-c++-12.1.1-1.fc37. Probably relevant part of the GCC 12 changelog: Eliminating uninitialized variables.

MWE:

#include <boost/test/unit_test.hpp>

struct my_precondition {
  boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id) {
    return false;
  }
};

BOOST_TEST_DECORATOR(*boost::unit_test::precondition(my_precondition()))
BOOST_AUTO_TEST_CASE(my_test) {
}

Output (live example):

$ g++ -Wall -O3 -c mwe.cpp
In file included from /usr/include/boost/function/detail/maybe_include.hpp:22,
                 from /usr/include/boost/function/function1.hpp:11,
                 from /usr/include/boost/test/tree/decorator.hpp:30,
                 from /usr/include/boost/test/tools/fpc_tolerance.hpp:19,
                 from /usr/include/boost/test/tools/fpc_op.hpp:19,
                 from /usr/include/boost/test/test_tools.hpp:54,
                 from /usr/include/boost/test/unit_test.hpp:18,
                 from mwe.cpp:1:
In member function ‘void boost::function1<R, T1>::assign_to_own(const boost::function1<R, T1>&) [with R = boost::test_tools::assertion_result; T0 = long unsigned int]’,
    inlined from ‘boost::function1<R, T1>::function1(const boost::function1<R, T1>&) [with R = boost::test_tools::assertion_result; T0 = long unsigned int]’ at /usr/include/boost/function/function_template.hpp:746:26,
    inlined from ‘boost::function<R(T0)>::function(const self_type&) [with R = boost::test_tools::assertion_result; T0 = long unsigned int]’ at /usr/include/boost/function/function_template.hpp:1105:76,
    inlined from ‘boost::unit_test::decorator::precondition::precondition(predicate_t)’ at /usr/include/boost/test/tree/decorator.hpp:280:61,
    inlined from ‘void __static_initialization_and_destruction_0(int, int)’ at mwe.cpp:9:1,
    inlined from ‘(static initializers for mwe.cpp)’ at mwe.cpp:11:1:
/usr/include/boost/function/function_template.hpp:910:22: warning: ‘*(unsigned char (*)[24])((char*)&<unnamed> + offsetof(boost::predicate_t, boost::function<boost::test_tools::assertion_result(long unsigned int)>::<unnamed>.boost::function1<boost::test_tools::assertion_result, long unsigned int>::<unnamed>.boost::function_base::functor))’ is used uninitialized [-Wuninitialized]
  910 |           std::memcpy(this->functor.data, f.functor.data, sizeof(boost::detail::function::function_buffer));
      |           ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/test/unit_test.hpp:19:
mwe.cpp: In function ‘(static initializers for mwe.cpp)’:
mwe.cpp:9:71: note: ‘<anonymous>’ declared here
    9 | BOOST_TEST_DECORATOR(*boost::unit_test::precondition(my_precondition()))
      |                                                                       ^

boost::function + member function + noexcept => error

Code gives compile error in GCC, Clang, MSVC in C++17 mode:

#include <boost/function.hpp>
int func1(int) {
    return 0;
}
int func2(int) noexcept {
    return 0;
}
struct test_t {
    int mem_func1(int)  {
        return 0;
    }
    int mem_func2(int) noexcept {
        return 0;
    }
};
void test()
{
    boost::function1<int, int> f1(&func1); // OK
    boost::function1<int, int> f2(&func2); // OK
    boost::function2<int, test_t*, int> mf1(&test_t::mem_func1); // OK
    boost::function2<int, test_t*, int> mf2(&test_t::mem_func2); // error C2064: term does not evaluate to a function taking 2 arguments
}

C++20 compilation failure disconnecting slots with boost::bind

The following test program:

#include <boost/signals2/signal.hpp>
#include <boost/bind/bind.hpp>

void ConnectedFunc(void)
{
}

int main()
{
    using namespace boost::placeholders;

    boost::signals2::signal<void()> sig;

    // connect
    sig.connect(boost::bind(&ConnectedFunc));

    // disconnect
    sig.disconnect(boost::bind(&ConnectedFunc));
}

Compiles fine with g++ -std=c++17 main.cc, but fails with g++ -std=c++20 main.cc at the site of the disconnect call.

The problem seems to be related to the operator== for the type returned by boost::bind (error from gcc 10, but a similar error is reported by other versions of gcc and clang):

<snip>
/usr/include/boost/signals2/detail/signal_template.hpp:530:46: error: return type of ‘boost::_bi::bind_t<bool, boost::_bi::equal, boost::_bi::list2<boost::_bi::bind_t<R, F, L>, typename boost::_bi::add_value<A4>::type> > boost::_bi::operator==(const boost::_bi::bind_t<R, F, L>&, A2) [with R = void; F = void (*)(); L = boost::_bi::list0; A2 = boost::function<void()>; typename boost::_bi::add_value<A4>::type = boost::_bi::value<boost::function<void()> >]’ is not ‘bool’
/usr/include/boost/signals2/detail/signal_template.hpp:530:46: note: used as rewritten candidate for comparison of ‘boost::signals2::slot<void(), boost::function<void()> >::slot_function_type’ {aka ‘boost::function<void()>’} and ‘const boost::_bi::bind_t<void, void (*)(), boost::_bi::list0>’

I'm not sure if this is a bug with the signals2 library, a bug with the bind library, or whether this form of disconnect is no longer supported and the documentation just doesn't make it clear, but since the point at which I encountered it was in using the signals2 library I'm reporting it here first.

Cppcheck Travis job does nothing in a verbose way

The Cppcheck job (https://travis-ci.org/boostorg/function/jobs/432021217) fills the Travis log with warnings about a function not being inlined, then concludes with the final blow of:

cppcheck: error: could not find or open any of the paths given.

and succeeds.

I can't help but notice that Function had a perfectly serviceable .travis.yml configuration which I had put in place, that admittedly needed to be brought up to date but nevertheless provided much more platform coverage (important for a widely used library such as Function.) This has been deleted. Consider reinstating it.

May be uninitialized warnings

gcc.compile.c++ bin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden\function_n_test.o
In file included from ./boost/function/detail/maybe_include.hpp:15,
                 from ./boost/function/function0.hpp:11,
                 from ./boost/test/execution_monitor.hpp:28,
                 from ./boost/test/impl/execution_monitor.ipp:28,
                 from ./boost/test/minimal.hpp:53,
                 from libs\function\test\function_n_test.cpp:10:
./boost/function/function_template.hpp: In function 'void test_construct_destroy_count()':
./boost/function/function_template.hpp:998:24: error: '*((void*)& f +8)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
             std::memcpy(this->functor.data, f.functor.data, sizeof(this->functor.data));
             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus.exe: all warnings being treated as errors

    "g++"   -std=c++03 -fvisibility-inlines-hidden -m64 -O3 -finline-functions -Wno-inline -Wall -Werror -fvisibility=hidden  -DBOOST_ALL_NO_LIB=1 -DNDEBUG  -I"." -c -o "bin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden\function_n_test.o" "libs\function\test\function_n_test.cpp"

...failed gcc.compile.c++ bin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden\function_n_test.o...
...skipped <pbin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden>function_n_test.exe for lack of <pbin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden>function_n_test.o...
...skipped <pbin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden>function_n_test.run for lack of <pbin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-03-iso\visibility-hidden>function_n_test.exe...
gcc.compile.c++ bin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-11-iso\visibility-hidden\function_n_test.o
In file included from ./boost/function/detail/maybe_include.hpp:15,
                 from ./boost/function/function0.hpp:11,
                 from ./boost/test/execution_monitor.hpp:28,
                 from ./boost/test/impl/execution_monitor.ipp:28,
                 from ./boost/test/minimal.hpp:53,
                 from libs\function\test\function_n_test.cpp:10:
./boost/function/function_template.hpp: In function 'void test_construct_destroy_count()':
./boost/function/function_template.hpp:998:24: error: '*((void*)& f +8)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
             std::memcpy(this->functor.data, f.functor.data, sizeof(this->functor.data));
             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus.exe: all warnings being treated as errors

    "g++"   -std=c++11 -fvisibility-inlines-hidden -m64 -O3 -finline-functions -Wno-inline -Wall -Werror -fvisibility=hidden  -DBOOST_ALL_NO_LIB=1 -DNDEBUG  -I"." -c -o "bin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-11-iso\visibility-hidden\function_n_test.o" "libs\function\test\function_n_test.cpp"

...failed gcc.compile.c++ bin.v2\libs\function\test\function_n_test.test\gcc-8.2.0\release\cxxstd-11-iso\visibility-hidden\function_n_test.o...

Modular Boost C++ Libraries Request

We are in the process of making B2 build changes to all of the B2 build files
to support "modular" consumption of the Boost Libraries by users. See this list
post for some details: https://lists.boost.org/Archives/boost/2024/01/255704.php

The process requires making a variety of changes to make each Boost library
independent of the super-project structure. But the changes do not remove the
super-project structure or the comprehensive Boost release. The changes make
solely make it possible, optionally, for users, like package manages, to easily
consume libraries individually.

Generally the changes include:

  • Adding a libroot/build.jam.
  • Porting any functionality from libroot/jamfile to libroot/build.jam.
  • Moving boost-install declaration from libroot/build/jamfile is applicable.
  • Adjusting other B2 build files in the library, like test/jamfile, as needed.
  • Possible changes to C++ source files to remove includes relative to the
    super-project boostroot location.

Some examples of such changes:

We are asking how you would like us to handle the changes. We would prefer if
you allow the owners of the Boost.org GitHub project to make changes to B2
build files, as needed, to accomplish the changes. But understand
that you may want to manage the proposed changes yourself.

We previously sent emails to all known maintainers to fill out a form with their
preference. We are contacting you in this issue as we have not gotten a response
to that email. You can see the ongoing responses for that form and the responses
to these issues here https://github.com/users/grafikrobot/projects/1/views/6

We are now asking if you can reply directly to this issue to indicate your
preference of handling the changes. Please supply a response to this question
and close the issue (so that we can verify you are a maintainer).

How would you like the build changes to be processed?

  1. Pull request, reviewed and merged by a BOOSTORG OWNER.
  2. Pull request, reviewed and merged by YOU.
  3. Other. (please specify details in the reply)

Also please indicate any special instructions you want us to consider. Or other
information you want us to be aware of.

Thanks you, René

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.