public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/101831] Spurious maybe-uninitialized warning on std::array::size
Date: Mon, 16 Aug 2021 19:18:21 +0000	[thread overview]
Message-ID: <bug-101831-4-C0l8MZXHTi@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101831-4@http.gcc.gnu.org/bugzilla/>

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;
      |       ^

  reply	other threads:[~2021-08-16 19:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 16:13 [Bug c++/101831] New: " m101010a at gmail dot com
2021-08-16 19:18 ` msebor at gcc dot gnu.org [this message]
2022-01-21 21:32 ` [Bug tree-optimization/101831] " kim.walisch at gmail dot com
2022-01-24 21:31 ` [Bug tree-optimization/101831] [11/12 Regression] " msebor at gcc dot gnu.org
2022-01-27 21:34 ` msebor at gcc dot gnu.org
2022-01-28  2:03 ` pinskia at gcc dot gnu.org
2022-02-01 18:54 ` msebor at gcc dot gnu.org
2022-02-02  0:22 ` cvs-commit at gcc dot gnu.org
2022-02-02  0:24 ` [Bug tree-optimization/101831] [11 " msebor at gcc dot gnu.org
2022-04-21  7:50 ` rguenth at gcc dot gnu.org
2023-05-29 10:05 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101831-4-C0l8MZXHTi@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).