http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52924

             Bug #: 52924
           Summary: Using an std::function object as deleter of shared_ptr
                    in C++0x mode does not compile
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: j...@essi.fr


The following program fails to compile in C++0X mode :

#include <memory>
#include <functional>

class A {};
A a;

void fdeleter(A *pa) {}
std::function<void(A *)> deleter = fdeleter;

std::shared_ptr<A> spa(&a, deleter);

int main()
{}

Note that
- replacing deleter by fdeleter (or a lambda) in spa definition works;
- compiling in non-c++0x mode (replacing std by std::tr1 works as well
- this program compiles OK in c++0x mode with gcc-4.6.x

gcc-version : gcc-4.7.0 (64 bits)

system : Linux Fedora 15 (64 bits)

gcc configuration: (gcc -v)

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/test/gcc-4.7.0/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr/local/test/gcc-4.7.0
--with-local-prefix=/usr/local/test/gcc-4.7.0 --enable-threads
--enable-languages=ada,c,c++,fortran,java,objc,obj-c++
--with-gmp-lib=/usr/lib64 --with-mpfr-lib=/usr/lib64 --with-mpc-lib=/usr/lib64
--disable-multilib
Thread model: posix
gcc version 4.7.0 (GCC) 

Compilation command and compiler output:

g++ -g -Wall -Wextra -std=c++0x -o deleter-bug-c++0x deleter-bug-c++0x.cpp

deleter-bug-c++0x.cpp:7:6: warning: unused parameter ‘pa’ [-Wunused-parameter]
In file included from
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr.h:52:0,
                 from
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/memory:87,
                 from deleter-bug-c++0x.cpp:1:
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr_base.h:
In instantiation of ‘class std::_Sp_counted_deleter<A*,
std::function<void(A*)>, std::allocator<int>, (__gnu_cxx::_Lock_policy)2u>’:
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr_base.h:474:8:
  required from ‘std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with
_Ptr = A*; _Deleter = std::function<void(A*)>; __gnu_cxx::_Lock_policy _Lp =
(__gnu_cxx::_Lock_policy)2u]’
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr_base.h:776:37:
  required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*, _Deleter)
[with _Tp1 = A; _Deleter = std::function<void(A*)>; _Tp = A;
__gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr.h:130:37:
  required from ‘std::shared_ptr<_Tp>::shared_ptr(_Tp1*, _Deleter) [with _Tp1 =
A; _Deleter = std::function<void(A*)>; _Tp = A]’
deleter-bug-c++0x.cpp:10:35:   required from here
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr_base.h:324:11:
error: looser throw specifier for ‘virtual std::_Sp_counted_deleter<A*,
std::function<void(A*)>, std::allocator<int>,
(__gnu_cxx::_Lock_policy)2u>::~_Sp_counted_deleter()’
/usr/local/test/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/shared_ptr_base.h:116:7:
error:   overriding ‘std::_Sp_counted_base<_Lp>::~_Sp_counted_base() noexcept
(true) [with __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’

Compilation exited abnormally with code 1 at Tue Apr 10 10:00:29

Reply via email to