public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101780] New: Missing initializers whereas structure has default initializers
@ 2021-08-04 19:53 deco33000 at yandex dot com
  2021-08-05 11:39 ` [Bug c++/101780] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: deco33000 at yandex dot com @ 2021-08-04 19:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101780
           Summary: Missing initializers whereas structure has default
                    initializers
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: deco33000 at yandex dot com
  Target Milestone: ---

Hi,

The issue is a false positive warning being issued whereas even if there are
missing initializers, the rest of the struct is default initialized.


// Type your code here, or load an example.
#include <iostream>
#include <vector>
using namespace std;

struct A {
  union {
    int i = 82, j;
  };
  int a = 98, b = 22;
};

int main() {
  A polo = {.a = 45};

  cout << polo.a << endl;
  cout << polo.i << endl;

  return 0;
}
warning: missing initializer for member 'A::<anonymous>'
[-Wmissing-field-initializers]


Try on godbolt:
https://godbolt.org/z/ohnWPqcE5

Can you confirm it is the intended behavior?
If so, could we make the message clearer, adding: "the following designated
fields X,Y,Z will be default initialized. P,Q,R are left uninitialized."

That way, it is much more useful as a warning, instead of making the dev fear
of undefined behavior, when there is not.

Thanks,

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

end of thread, other threads:[~2023-05-04 16:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 19:53 [Bug c++/101780] New: Missing initializers whereas structure has default initializers deco33000 at yandex dot com
2021-08-05 11:39 ` [Bug c++/101780] " redi at gcc dot gnu.org
2021-08-05 14:17 ` deco33000 at yandex dot com
2021-08-05 16:00 ` redi at gcc dot gnu.org
2021-08-06  5:01 ` deco33000 at yandex dot com
2023-05-04 16:11 ` 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).