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

* [Bug c++/52924] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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 ` redi at gcc dot gnu.org
  2012-04-10 10:23 ` [Bug c++/52924] [4.7 Regression] " redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-10  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-04-10
         AssignedTo|unassigned at gcc dot       |redi at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-10 09:07:57 UTC ---
Mine


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

* [Bug c++/52924] [4.7 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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 ` redi at gcc dot gnu.org
  2012-04-10 12:56 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-10 10:23 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
   Target Milestone|---                         |4.7.1
            Summary|Using an std::function      |[4.7 Regression] Using an
                   |object as deleter of        |std::function object as
                   |shared_ptr in C++0x mode    |deleter of shared_ptr in
                   |does not compile            |C++0x mode does not compile

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-10 10:22:41 UTC ---
The problem is that std::function::~function should be noexcept, but isn't
because PR 50043 is not fixed on the 4.7 branch

I'll fix it by adding a noexcept destructor to _Sp_counted_deleter and/or
_Sp_counter_deleter::_My_deleter


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

* [Bug c++/52924] [4.7 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-10 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-10 12:55:40 UTC ---
another testcase showing a similar bug:

#include <memory>

template<typename T>
struct Alloc : std::allocator<T>
{
    template<typename U> struct rebind { typedef Alloc<U> other; };

    template<typename U> Alloc(const Alloc<U>&) { }

    Alloc() = default;
    ~Alloc() noexcept(false) { }
};

Alloc<A> alloc;

auto x = std::allocate_shared<A>(alloc);


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

* [Bug c++/52924] [4.7 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-04-10 17:04 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|jpr at essi dot fr          |

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-04-10 17:03:55 UTC ---
Thanks for handling this, Jon. I would recommend adding the testcase to
mainline too.


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

* [Bug c++/52924] [4.7/4.8 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (3 preceding siblings ...)
  2012-04-10 17:04 ` paolo.carlini at oracle dot com
@ 2012-04-11  9:31 ` redi at gcc dot gnu.org
  2012-04-11 10:30 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-11  9:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.6.3
            Summary|[4.7 Regression] Using an   |[4.7/4.8 Regression] Using
                   |std::function object as     |an std::function object as
                   |deleter of shared_ptr in    |deleter of shared_ptr in
                   |C++0x mode does not compile |C++0x mode does not compile

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-11 09:30:37 UTC ---
In fact even if ~function is noexcept the bug is still present for other
deleters and allocators with potentially-throwing destructors, so the bug's
present on trunk too.


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

* [Bug c++/52924] [4.7/4.8 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-04-11 10:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-04-11 10:29:55 UTC ---
I see, in a sense I'm more happy. Anyway the issue seems easy to fix, right?


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

* [Bug c++/52924] [4.7/4.8 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-11 10:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-11 10:34:04 UTC ---
Yes, very simple, I'll check it in tonight


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

* [Bug c++/52924] [4.7/4.8 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-11 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-11 22:54:59 UTC ---
Author: redi
Date: Wed Apr 11 22:54:53 2012
New Revision: 186363

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186363
Log:
    PR libstdc++/52924
    * include/bits/shared_ptr_base.h (_Sp_counted_deleter): Add
    user-defined destructor.
    (_Sp_counted_inplace): Likewise.
    * testsuite/20_util/shared_ptr/cons/52924.cc: New.
    * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error
    line numbers.

Added:
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/cons/52924.cc
      - copied, changed from r186362,
trunk/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/shared_ptr_base.h
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc


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

* [Bug c++/52924] [4.7/4.8 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-11 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-11 23:13:49 UTC ---
Author: redi
Date: Wed Apr 11 23:13:44 2012
New Revision: 186367

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186367
Log:
    PR libstdc++/52924
    * include/bits/shared_ptr_base.h (_Sp_counted_deleter): Add
    user-defined destructor.
    (_Sp_counted_inplace): Likewise.
    * testsuite/20_util/shared_ptr/cons/52924.cc: New.
    * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error
    line numbers.

Added:
   
branches/gcc-4_7-branch/libstdc++-v3/testsuite/20_util/shared_ptr/cons/52924.cc
      - copied, changed from r186360,
branches/gcc-4_7-branch/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/bits/shared_ptr_base.h
   
branches/gcc-4_7-branch/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc


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

* [Bug c++/52924] [4.7/4.8 Regression] Using an std::function object as deleter of shared_ptr in C++0x mode does not compile
  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
                   ` (8 preceding siblings ...)
  2012-04-11 23:14 ` redi at gcc dot gnu.org
@ 2012-04-11 23:15 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-11 23:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-11 23:14:43 UTC ---
fixed for 4.7.1


^ 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).