public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110836] New: g++ should report when there is no way to create structure or class
@ 2023-07-28  6:08 andris at gcc dot gnu.org
  2023-07-28  6:20 ` [Bug c++/110836] [C++20] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andris at gcc dot gnu.org @ 2023-07-28  6:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110836
           Summary: g++ should report when there is no way to create
                    structure or class
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andris at gcc dot gnu.org
  Target Milestone: ---

Created attachment 55651
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55651&action=edit
example

GCC should report when there is no way to create structure or class instance.

At least warning would be required (preferably enabled by default or -Wall)
It could even be an error 

Possible reasons why it could be impossible to create object (list can be
incomplete):
- at least one deleted constructor present and no other constructors
- only copy constructor
- only private destructor
- only private constructor and no static methods (should exclude possibility of
factory methods as there is no way to detect them from declaration only when
static methods are present)

Currently problem is only detected when there is an attempt to create object,
but it should be also detectable from header files only

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

* [Bug c++/110836] [C++20] g++ should report when there is no way to create structure or class
  2023-07-28  6:08 [Bug c++/110836] New: g++ should report when there is no way to create structure or class andris at gcc dot gnu.org
@ 2023-07-28  6:20 ` pinskia at gcc dot gnu.org
  2023-07-28  6:43 ` andris at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-28  6:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Summary|g++ should report when      |[C++20] g++ should report
                   |there is no way to create   |when there is no way to
                   |structure or class          |create structure or class

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually, in C++11-C++17 you can create it like:
```
struct Foo
{
    Foo(const Foo&) = delete;
};

Foo a{};
```

Only in C++20+ there is no way to create it.

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

* [Bug c++/110836] [C++20] g++ should report when there is no way to create structure or class
  2023-07-28  6:08 [Bug c++/110836] New: g++ should report when there is no way to create structure or class andris at gcc dot gnu.org
  2023-07-28  6:20 ` [Bug c++/110836] [C++20] " pinskia at gcc dot gnu.org
@ 2023-07-28  6:43 ` andris at gcc dot gnu.org
  2023-07-28  8:20 ` redi at gcc dot gnu.org
  2023-07-28  8:21 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: andris at gcc dot gnu.org @ 2023-07-28  6:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andris Pavenis <andris at gcc dot gnu.org> ---
Warning would allow to detected problem earlier.

Otherwise it could only be detected later in case when affected structure or
class is part of an library and its objects are not created directly inside the
library. In this case the inability to create objects may only be detected
later when building other packages which uses this library

In our case the problem appeared when replacing deriving from
boost::noncopyable with added deleted copy constructor and deleted assignment
operators.

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

* [Bug c++/110836] [C++20] g++ should report when there is no way to create structure or class
  2023-07-28  6:08 [Bug c++/110836] New: g++ should report when there is no way to create structure or class andris at gcc dot gnu.org
  2023-07-28  6:20 ` [Bug c++/110836] [C++20] " pinskia at gcc dot gnu.org
  2023-07-28  6:43 ` andris at gcc dot gnu.org
@ 2023-07-28  8:20 ` redi at gcc dot gnu.org
  2023-07-28  8:21 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-28  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Some classes are supposed to be impossible to create, e.g. the monostate
pattern where the class has static members and the whole API is in terms of
static members functions.

If you don't notice a class cannot be created until users compile your library
then you are missing some tests for that class. Why do you have a class that
has never been tested even once?

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

* [Bug c++/110836] [C++20] g++ should report when there is no way to create structure or class
  2023-07-28  6:08 [Bug c++/110836] New: g++ should report when there is no way to create structure or class andris at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-28  8:20 ` redi at gcc dot gnu.org
@ 2023-07-28  8:21 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-28  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andris Pavenis from comment #0)
> At least warning would be required (preferably enabled by default or -Wall)
> It could even be an error 

No it couldn't.

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

end of thread, other threads:[~2023-07-28  8:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-28  6:08 [Bug c++/110836] New: g++ should report when there is no way to create structure or class andris at gcc dot gnu.org
2023-07-28  6:20 ` [Bug c++/110836] [C++20] " pinskia at gcc dot gnu.org
2023-07-28  6:43 ` andris at gcc dot gnu.org
2023-07-28  8:20 ` redi at gcc dot gnu.org
2023-07-28  8:21 ` 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).