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

            Bug ID: 90740
           Summary: regression - Incorrect warning (is used uninitialized
                    in this function)
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: v at vsamko dot com
  Target Milestone: ---

We are not "using" `buf` there. We are passing it by reference, which is a
valid code and it shouldn't raise any warnings (for example, it can be a buffer
pointer that we pass as a destination to memcpy, and it does not need to be
initialised).

If we replace "int SIZE = 100" with "constexpr int SIZE = 100" then the warning
goes away, which doesn't make any sense.

g++ 7 and 8 don't show this warning on this code.

Also, why does the warning refers to the variable as "<anonymous>" when it
clearly has a name?

=========
template<typename T, typename... U>
void bar(T t, U... u) {
    t(u...);
}

template<typename T>
void doit(T) {}

int SIZE = 100;

template<typename ...Vs>
void read(Vs & ...out) {
    char buf[SIZE];
    bar([&buf, &out...](auto&... column) { (doit(column), ...); }, out...);
}

int main() {
    int x1;
    read(x1);
}
=========


source>: In lambda function:

<source>:14:9: warning: '<anonymous>' is used uninitialized in this function
[-Wuninitialized]

   14 |     bar([&buf, &out...](auto&... column) { (doit(column), ...); },
out...);

      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<source>:13:10: note: '<anonymous>' was declared here

   13 |     char buf[SIZE];

      |          ^~~

Compiler returned: 0

Reply via email to