public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized
@ 2022-11-18 13:31 alvinhochun at gmail dot com
  2022-11-18 20:01 ` [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0 pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: alvinhochun at gmail dot com @ 2022-11-18 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2023-05-29 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 13:31 [Bug c++/107751] New: [11/12 regression] False positive -Wmaybe-uninitialized alvinhochun at gmail dot com
2022-11-18 20:01 ` [Bug c++/107751] [11/12/13 regression] False positive -Wmaybe-uninitialized at -O0 pinskia at gcc dot gnu.org
2022-11-18 20:03 ` pinskia at gcc dot gnu.org
2022-11-18 20:06 ` [Bug tree-optimization/107751] " mpolacek at gcc dot gnu.org
2022-12-20 15:56 ` rguenth at gcc dot gnu.org
2023-05-29 10:07 ` [Bug tree-optimization/107751] [11/12/13/14 " jakub 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).