public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104266] New: Temporaries with protected destructor are erroneously permitted
@ 2022-01-28  8:20 fchelnokov at gmail dot com
  2022-01-28 15:59 ` [Bug c++/104266] " de34 at live dot cn
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-28  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104266
           Summary: Temporaries with protected destructor are erroneously
                    permitted
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This is invalid code currently accepted by GCC:
```
struct A {
protected:
  ~A() { }
};

struct B : A {};

int main() {
    B b{};
}
```
but rejected in Clang and MSVC, because `B b{}` during aggregate initialization
implicitly creates a temporary `A{}`, which is not allowed in the context.

Demo: https://gcc.godbolt.org/z/Yehch5PzK

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

* [Bug c++/104266] Temporaries with protected destructor are erroneously permitted
  2022-01-28  8:20 [Bug c++/104266] New: Temporaries with protected destructor are erroneously permitted fchelnokov at gmail dot com
@ 2022-01-28 15:59 ` de34 at live dot cn
  2022-01-29  5:06 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: de34 at live dot cn @ 2022-01-28 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

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

--- Comment #1 from Jiang An <de34 at live dot cn> ---
I think this is CWG DR 2227 (https://wg21.link/cwg2227).

And IIUC although it is correct to reject this code, clang's error message is
wrong, because there's no temporary of type 'A' created due to guaranteed RVO
since C++17.

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

* [Bug c++/104266] Temporaries with protected destructor are erroneously permitted
  2022-01-28  8:20 [Bug c++/104266] New: Temporaries with protected destructor are erroneously permitted fchelnokov at gmail dot com
  2022-01-28 15:59 ` [Bug c++/104266] " de34 at live dot cn
@ 2022-01-29  5:06 ` pinskia at gcc dot gnu.org
  2022-01-29  5:14 ` pinskia at gcc dot gnu.org
  2022-01-29 17:25 ` fchelnokov at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-29  5:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-01-29

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So clang, ICC and MSVC all reject it for at least in C++17 mode (clang and ICC
accepted it for C++14).

Confirmed.

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

* [Bug c++/104266] Temporaries with protected destructor are erroneously permitted
  2022-01-28  8:20 [Bug c++/104266] New: Temporaries with protected destructor are erroneously permitted fchelnokov at gmail dot com
  2022-01-28 15:59 ` [Bug c++/104266] " de34 at live dot cn
  2022-01-29  5:06 ` pinskia at gcc dot gnu.org
@ 2022-01-29  5:14 ` pinskia at gcc dot gnu.org
  2022-01-29 17:25 ` fchelnokov at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-29  5:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is another example:
   class X { protected: ~X(); friend struct Y; }; 
   struct Y { X x = {}; }; 

int main() {
   Y b {}; 
}

But unlike the previous example, this one is rejected by clang in C++14 but
accepted for C++11.
And even accepted by ICC for C++17 and C++14.
Note it is rejected by MSVC though.

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

* [Bug c++/104266] Temporaries with protected destructor are erroneously permitted
  2022-01-28  8:20 [Bug c++/104266] New: Temporaries with protected destructor are erroneously permitted fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2022-01-29  5:14 ` pinskia at gcc dot gnu.org
@ 2022-01-29 17:25 ` fchelnokov at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-29 17:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
In your last example, I think Clang is right, because `Y` is not an aggregate
in C++11 due to the presence of default member initializer. And it becomes an
aggregate only in C++14.

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

end of thread, other threads:[~2022-01-29 17:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28  8:20 [Bug c++/104266] New: Temporaries with protected destructor are erroneously permitted fchelnokov at gmail dot com
2022-01-28 15:59 ` [Bug c++/104266] " de34 at live dot cn
2022-01-29  5:06 ` pinskia at gcc dot gnu.org
2022-01-29  5:14 ` pinskia at gcc dot gnu.org
2022-01-29 17:25 ` fchelnokov at gmail dot com

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