public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
@ 2022-03-08 23:33 kirshamir at gmail dot com
  2022-03-09  9:23 ` [Bug c++/104850] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: kirshamir at gmail dot com @ 2022-03-08 23:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

            Bug ID: 104850
           Summary: Instantiating a destructor for a template class too
                    early, before the calling destructor is seen - rejects
                    valid code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kirshamir at gmail dot com
  Target Milestone: ---

The following code is rejected as trying to use incomplete type, while when the
actual use would actually appear the type would be complete:

template<typename T>
struct uptr {
    uptr(nullptr_t) {}
    ~uptr() {
        delete (new T);
    }
};

class A
{
public:
  A();
  ~A();
private:
  class B;
  uptr<B> m_b = nullptr; // the dtor of uptr tries to be instantiated here
};

If we change the initialization of:
uptr<B> m_b = nullptr; 
To:
uptr<B> m_b {nullptr}; 

The destructor instantiation is delayed, till ~A() is seen, and the code can be
compiled.

See:
https://stackoverflow.com/questions/71397495/why-does-default-member-initializer-request-instantiation-of-unique-ptr-destru

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
@ 2022-03-09  9:23 ` rguenth at gcc dot gnu.org
  2022-03-09  9:34 ` kirshamir at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-03-09  9:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-03-09
           Keywords|                            |rejects-valid
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I get

t.ii:3:10: error: unknown type name 'nullptr_t'
    uptr(nullptr_t) {}
         ^

please fix your example.

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
  2022-03-09  9:23 ` [Bug c++/104850] " rguenth at gcc dot gnu.org
@ 2022-03-09  9:34 ` kirshamir at gmail dot com
  2022-03-10  4:35 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kirshamir at gmail dot com @ 2022-03-09  9:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

--- Comment #2 from Amir Kirsh <kirshamir at gmail dot com> ---
// adding the required include to the example

#include <cstddef> // for nullptr_t

template<typename T>
struct uptr {
    uptr(nullptr_t) {}
    ~uptr() {
        delete (new T);
    }
};

class A
{
public:
  A();
  ~A();
private:
  class B;
  uptr<B> m_b = nullptr; // the dtor of uptr tries to be instantiated here
};

https://wandbox.org/permlink/rJeeB3Sliey6tGzR

If we change the initialization of:
uptr<B> m_b = nullptr; 
To:
uptr<B> m_b {nullptr}; 

Relevant SO post:
https://stackoverflow.com/questions/71397495/why-does-default-member-initializer-request-instantiation-of-unique-ptr-destru/71402270#71402270

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
  2022-03-09  9:23 ` [Bug c++/104850] " rguenth at gcc dot gnu.org
  2022-03-09  9:34 ` kirshamir at gmail dot com
@ 2022-03-10  4:35 ` pinskia at gcc dot gnu.org
  2022-03-10  4:41 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-10  4:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang and ICC also reject this for the same reason as GCC.
MSVC on the other hand accepts this.

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
                   ` (2 preceding siblings ...)
  2022-03-10  4:35 ` pinskia at gcc dot gnu.org
@ 2022-03-10  4:41 ` pinskia at gcc dot gnu.org
  2024-02-23 14:29 ` de34 at live dot cn
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-10  4:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Interesting if I put the definition of the class A::B at the end of the file,
the code works ....

I wonder if this is because of some ABI issue where A::A as a base class is
created ....

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
                   ` (3 preceding siblings ...)
  2022-03-10  4:41 ` pinskia at gcc dot gnu.org
@ 2024-02-23 14:29 ` de34 at live dot cn
  2024-03-05 12:30 ` benni.buch at gmail dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: de34 at live dot cn @ 2024-02-23 14:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #5 from Jiang An <de34 at live dot cn> ---
Clang started to accept this since Clang 16. https://godbolt.org/z/c6vGzTP48

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
                   ` (4 preceding siblings ...)
  2024-02-23 14:29 ` de34 at live dot cn
@ 2024-03-05 12:30 ` benni.buch at gmail dot com
  2024-03-05 12:31 ` benni.buch at gmail dot com
  2024-03-07  4:52 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: benni.buch at gmail dot com @ 2024-03-05 12:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

Benjamin Buch <benni.buch at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benni.buch at gmail dot com

--- Comment #6 from Benjamin Buch <benni.buch at gmail dot com> ---
I think this is a sub-case of Bug 104850

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
                   ` (5 preceding siblings ...)
  2024-03-05 12:30 ` benni.buch at gmail dot com
@ 2024-03-05 12:31 ` benni.buch at gmail dot com
  2024-03-07  4:52 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: benni.buch at gmail dot com @ 2024-03-05 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

--- Comment #7 from Benjamin Buch <benni.buch at gmail dot com> ---
Sorry wrong number; Bug 114076

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

* [Bug c++/104850] Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code
  2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
                   ` (6 preceding siblings ...)
  2024-03-05 12:31 ` benni.buch at gmail dot com
@ 2024-03-07  4:52 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-07  4:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104850

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=96645

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Seems related to PR 96645 (and CWG2335).

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

end of thread, other threads:[~2024-03-07  4:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 23:33 [Bug c++/104850] New: Instantiating a destructor for a template class too early, before the calling destructor is seen - rejects valid code kirshamir at gmail dot com
2022-03-09  9:23 ` [Bug c++/104850] " rguenth at gcc dot gnu.org
2022-03-09  9:34 ` kirshamir at gmail dot com
2022-03-10  4:35 ` pinskia at gcc dot gnu.org
2022-03-10  4:41 ` pinskia at gcc dot gnu.org
2024-02-23 14:29 ` de34 at live dot cn
2024-03-05 12:30 ` benni.buch at gmail dot com
2024-03-05 12:31 ` benni.buch at gmail dot com
2024-03-07  4:52 ` pinskia 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).