bind1st fails to compile when argument type is a constant reference
Jonathan Wakely
jwakely.gcc@gmail.com
Fri Nov 18 14:39:00 GMT 2011
2011/11/18 Krzysztof Żelechowski:
> First of all, the FAQ
> <http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.standard_bugs> says:
>>
>> a public list of the library defects is occasionally published here
>> <http://www.open-std.org/jtc1/sc22/wg21/>.
>
> Please do not do that. If the page is converted to plain text or printed,
> this sentence becomes nonsense.
Yup, I've fixed a few cases like that in the docs but there are many
remaining. Patches welcome.
> Now to the point. The following code does not compile:
>>
>> #include <functional>
>> #include <string>
>> void trigger () { ::std:: bind1st (::std:: equal_to < int const & > (),
>> 0); }
>
> with the following error messages:
>>
>> g++ -g -Wall i109.cpp -o i109
>> In file included from /usr/include/c++/4.5/bits/stl_function.h:712:0,
>> from /usr/include/c++/4.5/functional:50,
>> from i109.cpp:1:
>> /usr/include/c++/4.5/backward/binders.h: In instantiation of
>> ‘std::binder1st<std::equal_to<const int&> >’:
>> i109.cpp:3:74: instantiated from here
>> /usr/include/c++/4.5/backward/binders.h:118:7: error: ‘typename
>> _Operation::result_type std::binder1st<_Operation>::operator()(typename
>> _Operation::second_argument_type&) const [with _Operation =
>> std::equal_to<const int&>, typename _Operation::result_type = bool, typename
>> _Operation::second_argument_type = const int&]’ cannot be overloaded
>> /usr/include/c++/4.5/backward/binders.h:112:7: error: with ‘typename
>> _Operation::result_type std::binder1st<_Operation>::operator()(const
>> typename _Operation::second_argument_type&) const [with _Operation =
>> std::equal_to<const int&>, typename _Operation::result_type = bool, typename
>> _Operation::second_argument_type = const int&]’
>
> This is LWG Issue 109
> <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#109> fix gone
> wild, in that the cure is worse than the disease.
> Workaround:
>>
>> #include <tr1/functional>
>> void foo (void)
>> {
>> ::std:: tr1:: bind
>> (::std:: equal_to < int const & > (), 0, ::std:: tr1:: placeholders:: _1);
>> }
>
> It is, however, difficult to come up with this workaround because the API
> documentation
> <http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01633.html> does
> not show how to call |::std:: bind|
Patches welcome.
> (only |::std:: bind1st|, which does not
> work, see above), and the error messages emitted by invalid calls are
> cryptic.
>
> Please fix and report to LWG if appropriate.
If you're just reporting the problem not suggesting how to fix it then
it's better to use bugzilla.
But in this case, binder1st is deprecated in C++11, I doubt anyone is
going to be motivated to deal with a defect report.
The workaround is simple, don't use equal_to<int const&>, just use equal_to<int>
More information about the Libstdc++
mailing list