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

            Bug ID: 128465
           Summary: Wrong -Wmaybe-uninitialized on an empty struct
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Laurent.Rineau__gcc at normalesup dot org
  Target Milestone: ---

Created attachment 66090
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66090&action=edit
test case

With the following code

```c++

struct Empty {};
struct S { char c; Empty empty; S() : c(0), empty() {} };
void g(const Empty&);
void f()
{
  S s;
  g(s.empty);
}

```

g++ version 16.2.1 (from Linux Fedora 45) triggers a -Wmaybe-uninitialized
warning with -O1:

```
$ g++ -Wmaybe-uninitialized -O1 -c go.cpp
go.cpp: In function ‘void f()’:
go.cpp:7:4: warning: ‘s’ may be used uninitialized [-Wmaybe-uninitialized]
    7 |   g(s.empty);
      |   ~^~~~~~~~~
go.cpp:3:6: note: by argument 1 of type ‘const Empty&’ to ‘void g(const
Empty&)’ declared here
    3 | void g(const Empty&);
      |      ^
go.cpp:6:5: note: ‘s’ declared here
    6 |   S s;
      |     ^
```

I think it should not, because:
  - the member `s.empty` was initialized
  - that member is an empty struct anyway.

Reply via email to