public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor
@ 2012-10-04 14:37 daniel.kruegler at googlemail dot com
  2012-10-05 20:53 ` [Bug c++/54812] " paolo.carlini at oracle dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-10-04 14:37 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54812
           Summary: [C++11] Delete expression doesn't respect access of
                    defaulted destructor
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com
                CC: paolo@gcc.gnu.org


While working on a further simplification of the is_constructible traits using
gcc 4.8.0 20120930 (experimental) with the compiler flags

-Wall -pedantic -std=c++11

the following program demonstrates that private access of a *defaulted*
destructor is not properly respected during delete expressions:

//--------------------
#include <new>

template<class T>
T&& declval();

struct P1 {
private:
  ~P1();
};

struct P2 {
  ~P2() = delete;
};

struct P3 {
private:
  ~P3() = default;
};

typedef decltype(::delete declval<P1*>()) t1;  // #20
typedef decltype(::delete declval<P2*>()) t2;  // #21
typedef decltype(::delete declval<P3*>()) t3;  // #22 *Not* detected
//--------------------

This program produces only two errors instead of the expected three:

"main.cpp|8|error: 'P1::~P1()' is private|
 main.cpp|20|error: within this context|
 main.cpp|21|error: use of deleted function 'P2::~P2()'|
 main.cpp|12|error: declared here|
"

According to [expr.delete] p10 access control shall be done for the destructor.


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
@ 2012-10-05 20:53 ` paolo.carlini at oracle dot com
  2012-10-05 21:00 ` daniel.kruegler at googlemail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-05 20:53 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-05
     Ever Confirmed|0                           |1

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-05 20:53:35 UTC ---
Uhm, this is not trivial to fix. The difference between P1 and P3 is that for
the former from build_delete we call build_dtor_call which eventually also
calls the required perform_or_defer_access_check, whereas for the latter the
function just notices that TYPE_HAS_TRIVIAL_DESTRUCTOR and early returns (via
build_op_delete_call). Arguably, a TYPE_HAS_TRIVIAL_DESTRUCTOR true for a
destructor which actually is private and can't be called sounds a bit strange
but for sure the choice makes sense wrt the rest of the front-end and the
standard... I'll double check soon a few things.

Anyway, here, I only wanted to ask you if this is a show-stopper for your work,
because I don't know how much time it will take.


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
  2012-10-05 20:53 ` [Bug c++/54812] " paolo.carlini at oracle dot com
@ 2012-10-05 21:00 ` daniel.kruegler at googlemail dot com
  2012-10-05 21:08 ` paolo.carlini at oracle dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-10-05 21:00 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-10-05 21:00:31 UTC ---
(In reply to comment #1)
> Anyway, here, I only wanted to ask you if this is a show-stopper for your work,
> because I don't know how much time it will take.

While I think that this should be fixed, it will only prevent that I would
directly convert is_constructible to use the combined 

::delete ::new ((void*) nullptr) T(args) 

expression. Our current implementation is not sensitive to this problem,
because we use is_destructible within. I noticed that there are still a bunches
of opportunities to simplify is_constructible (and friends) because a lot of
previous compiler defects have been fixed. So, really no need to hurry!


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
  2012-10-05 20:53 ` [Bug c++/54812] " paolo.carlini at oracle dot com
  2012-10-05 21:00 ` daniel.kruegler at googlemail dot com
@ 2012-10-05 21:08 ` paolo.carlini at oracle dot com
  2012-10-05 21:10 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-05 21:08 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-05 21:08:04 UTC ---
Of course it should be fixed, it *must* be fixed, actually! And it's really
annoying that this bug affecting private defaulted destructors (which, I bet,
aren't that common for most programs not using SFINAE tricks!?!) is preventing
us from deploying right now the very elegant ::delete ::new pattern which
otherwise finally works pretty well. What can I add? Do your best, and thanks
again!


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (2 preceding siblings ...)
  2012-10-05 21:08 ` paolo.carlini at oracle dot com
@ 2012-10-05 21:10 ` paolo.carlini at oracle dot com
  2012-10-05 23:26 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-05 21:10 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-05 21:10:25 UTC ---
Let's ask Jason right now, if he can see a smart way to do access control on
defaulted destructors...


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (3 preceding siblings ...)
  2012-10-05 21:10 ` paolo.carlini at oracle dot com
@ 2012-10-05 23:26 ` paolo.carlini at oracle dot com
  2012-10-06  8:12 ` daniel.kruegler at googlemail dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-05 23:26 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-05 23:25:47 UTC ---
By the way, this compiles:

struct P3 {
private:
  ~P3() = default;
};

P3 p3;

thus there is little hope that we get an error for #22 ..


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (4 preceding siblings ...)
  2012-10-05 23:26 ` paolo.carlini at oracle dot com
@ 2012-10-06  8:12 ` daniel.kruegler at googlemail dot com
  2013-05-30 20:40 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-10-06  8:12 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-10-06 08:11:48 UTC ---
(In reply to comment #5)
I double-checked whether this might be related to

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1507

from a different perspective, but I'm pretty sure it isn't. 12.4 p11 seems very
clear that the destructor would be called implicitly here and that access
checking happens.


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (5 preceding siblings ...)
  2012-10-06  8:12 ` daniel.kruegler at googlemail dot com
@ 2013-05-30 20:40 ` jason at gcc dot gnu.org
  2013-06-12 11:32 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jason at gcc dot gnu.org @ 2013-05-30 20:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Various places in the compiler need to be updated to not assume that trivial
implies callable.


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (6 preceding siblings ...)
  2013-05-30 20:40 ` jason at gcc dot gnu.org
@ 2013-06-12 11:32 ` redi at gcc dot gnu.org
  2013-07-26 12:34 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-12 11:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |redi at gcc dot gnu.org

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 57595 has been marked as a duplicate of this bug. ***


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (7 preceding siblings ...)
  2013-06-12 11:32 ` redi at gcc dot gnu.org
@ 2013-07-26 12:34 ` redi at gcc dot gnu.org
  2013-07-26 12:35 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-26 12:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 56429 has been marked as a duplicate of this bug. ***


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (8 preceding siblings ...)
  2013-07-26 12:34 ` redi at gcc dot gnu.org
@ 2013-07-26 12:35 ` redi at gcc dot gnu.org
  2013-07-26 12:38 ` paolo.carlini at oracle dot com
  2014-05-06 21:56 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-26 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Paolo Carlini from comment #3)
> Of course it should be fixed, it *must* be fixed, actually! And it's really
> annoying that this bug affecting private defaulted destructors (which, I
> bet, aren't that common for most programs not using SFINAE tricks!?!)

The bug affects protected destructors too, and they're commonly used for base
classes to prevent deletion via pointer-to-base.  This bug means you can't make
them trivial by defining them as defaulted.

The problem isn't confined to delete expressions as the example from PR56429
shows:

class A
{
    A() = default;
};
struct B : A { };

B b;


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (9 preceding siblings ...)
  2013-07-26 12:35 ` redi at gcc dot gnu.org
@ 2013-07-26 12:38 ` paolo.carlini at oracle dot com
  2014-05-06 21:56 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-26 12:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Jason call if we want this to be a P2. Well, maybe some wrong code bugs I
recently bumped to P2 should be P1 ;)


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

* [Bug c++/54812] [C++11] Delete expression doesn't respect access of defaulted destructor
  2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
                   ` (10 preceding siblings ...)
  2013-07-26 12:38 ` paolo.carlini at oracle dot com
@ 2014-05-06 21:56 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-06 21:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hs at xmission dot com

--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 61087 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2014-05-06 21:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-04 14:37 [Bug c++/54812] New: [C++11] Delete expression doesn't respect access of defaulted destructor daniel.kruegler at googlemail dot com
2012-10-05 20:53 ` [Bug c++/54812] " paolo.carlini at oracle dot com
2012-10-05 21:00 ` daniel.kruegler at googlemail dot com
2012-10-05 21:08 ` paolo.carlini at oracle dot com
2012-10-05 21:10 ` paolo.carlini at oracle dot com
2012-10-05 23:26 ` paolo.carlini at oracle dot com
2012-10-06  8:12 ` daniel.kruegler at googlemail dot com
2013-05-30 20:40 ` jason at gcc dot gnu.org
2013-06-12 11:32 ` redi at gcc dot gnu.org
2013-07-26 12:34 ` redi at gcc dot gnu.org
2013-07-26 12:35 ` redi at gcc dot gnu.org
2013-07-26 12:38 ` paolo.carlini at oracle dot com
2014-05-06 21:56 ` 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).