https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101831
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 Last reconfirmed| |2021-08-16 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- -Wmaybe-uninitialized is also issued when an uninitialized object is passed by reference to a const-qualified argument. This includes passing the address of an such object to the implicit this pointer in calls to member functions. This form of the warning runs very early on and before any function calls have been inlined, so it can't tell that the function doesn't actually read from the uninitialized object. The same effect can be reproduced in C in a call to a non-member function (see below). It's possible to run the early uninitialized pass later but probably not without introducing some false negatives. I'm not sure that the std::array use case is common enough to justify the potential for the false negatives (or conversely, that the potential is significant enough not to avoid the false positives). So confirmed. It requires some thought and testing. $ cat a.c && gcc -S -Wall -Wextra a.c inline __attribute__ ((always_inline)) int f (const int *p) { (void)&p; return 0; } int g (void) { int i; return f (&i); } a.c: In function ‘g’: a.c:7:10: warning: ‘i’ may be used uninitialized [-Wmaybe-uninitialized] 7 | return f (&i); | ^~~~~~ a.c:2:5: note: by argument 1 of type ‘const int *’ to ‘f’ declared here 2 | int f (const int *p) { (void)&p; return 0; } | ^ a.c:6:7: note: ‘i’ declared here 6 | int i; | ^