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

            Bug ID: 124380
           Summary: False-positive -Wuninitialized warning when using
                    -ftrivial-auto-var-init
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abbeyj+gcc at gmail dot com
  Target Milestone: ---

When compiling the following with `-O1 -Wall -ftrivial-auto-var-init=zero`, a
-Wuninitialized warning is produced:

```
int get();
void sink(const int &);

inline void two() {
    const int & result = get();
    sink(result);
}

void one() {
    two();
}
```

Output:
> $ g++ -O1 -Wall -ftrivial-auto-var-init=zero -c uninit.cpp
> In function ‘void two()’,
>     inlined from ‘void one()’ at uninit.cpp:10:8:
> uninit.cpp:5:30: warning: ‘D.2801’ is used uninitialized [-Wuninitialized]
>     5 |     const int & result = get();
>       |                              ^
> uninit.cpp:5:30: note: ‘D.2801’ was declared here
>     5 |     const int & result = get();
>       |                              ^


This looks like it started in GCC 12.1 (because that's when
-ftrivial-auto-var-init=zero was introduced) and is still reproducible on the
current trunk version available on Godbolt: https://godbolt.org/z/MW6vEGEce

This is extremely similar to Bug 107411 but while that bug is now fixed, this
still reproduces.

Reply via email to