public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52924] New: Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
@ 2012-04-10  8:15 jpr at essi dot fr
  2012-04-10  9:08 ` [Bug c++/52924] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jpr at essi dot fr @ 2012-04-10  8:15 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: jpr@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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-04-11 23:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-10  8:15 [Bug c++/52924] New: Using an std::function object as deleter of shared_ptr in C++0x mode does not compile jpr at essi dot fr
2012-04-10  9:08 ` [Bug c++/52924] " redi at gcc dot gnu.org
2012-04-10 10:23 ` [Bug c++/52924] [4.7 Regression] " redi at gcc dot gnu.org
2012-04-10 12:56 ` redi at gcc dot gnu.org
2012-04-10 17:04 ` paolo.carlini at oracle dot com
2012-04-11  9:31 ` [Bug c++/52924] [4.7/4.8 " redi at gcc dot gnu.org
2012-04-11 10:30 ` paolo.carlini at oracle dot com
2012-04-11 10:34 ` redi at gcc dot gnu.org
2012-04-11 22:55 ` redi at gcc dot gnu.org
2012-04-11 23:14 ` redi at gcc dot gnu.org
2012-04-11 23:15 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).