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

            Bug ID: 107751
           Summary: [11/12 regression] False positive
                    -Wmaybe-uninitialized
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alvinhochun at gmail dot com
  Target Milestone: ---

This test case produces false-positive -Wmaybe-uninitialized warnings:

===
template <class T1, class T2>
bool std_equal(T1* a1, T1* a2, T2* b1);

template <class T1, class T2>
bool std_equal(T1* a1, T1* a2, T2* b1, T2* b2);

template <class T1, class T2>
void f() {
    int a[3] = {1, 2, 3};
    T1* x    = a;
    T2* y    = a;
    std_equal(x, x + 3, y);
    std_equal(y, y + 3, x);
    std_equal(x, x + 3, y, y + 3);
    std_equal(y, y + 3, x, x + 3);
}

int main(int, char**) {
    f<int, int>();
    f<int, const int>();
    f<int, volatile int>();
    f<int, const volatile int>();
    f<const int, const int>();
    f<const int, volatile int>();
    f<const int, const volatile int>();
    f<volatile int, volatile int>();
    f<volatile int, const volatile int>();
    f<const volatile int, const volatile int>();
    return 0;
}
===

Output:

===
<source>: In function 'void f() [with T1 = const int; T2 = const int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const int*' to 'bool std_equal(T1*,
T1*, T2*) [with T1 = const int; T2 = const int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
<source>: In function 'void f() [with T1 = const int; T2 = volatile int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const int*' to 'bool std_equal(T1*,
T1*, T2*) [with T1 = const int; T2 = volatile int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
<source>: In function 'void f() [with T1 = const int; T2 = const volatile
int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const int*' to 'bool std_equal(T1*,
T1*, T2*) [with T1 = const int; T2 = const volatile int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
<source>: In function 'void f() [with T1 = const volatile int; T2 = const
volatile int]':
<source>:12:14: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   12 |     std_equal(x, x + 3, y);
      |     ~~~~~~~~~^~~~~~~~~~~~~
<source>:2:6: note: by argument 2 of type 'const volatile int*' to 'bool
std_equal(T1*, T1*, T2*) [with T1 = const volatile int; T2 = const volatile
int]' declared here
    2 | bool std_equal(T1* a1, T1* a2, T2* b1);
      |      ^~~~~~~~~
<source>:9:9: note: 'a' declared here
    9 |     int a[3] = {1, 2, 3};
      |         ^
===

Compiler Explorer: https://godbolt.org/z/KsM6herr9

Reply via email to