public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: mark_at_yahoo <markrubn@yahoo.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: __attribute__ to selectively disable -Wmaybe-uninitialized
Date: Fri, 23 Oct 2020 13:01:13 -0700	[thread overview]
Message-ID: <caf2f32f-3caf-fc89-0ca6-4c885a7b8ff1@yahoo.com> (raw)
In-Reply-To: <caf2f32f-3caf-fc89-0ca6-4c885a7b8ff1.ref@yahoo.com>

To disable warnings of the form:
file.cxx:307:23: warning: 'buffer' may be used uninitialized in this 
function [-Wmaybe-uninitialized]

I have to bracket the variable's declaration, its use later in the 
function, and sometimes both, with:
#pragma GCC diagnostic push	
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
// code here
#pragma GCC diagnostic pop

The necessity to add many of these pragmas makes the code difficult to 
read. Is there a variable attribute that could be used instead, 
something like:
char	*buffer __attribute__((uninitialized));

I can't find anything similar in the "Common Variable Attributes" 
section of the docs.

If there isn't, could one be added? If local variables have attributes 
that are maintained throughout the compiler phases it seems it would be 
simple to check for one immediately before printing the warning, no 
matter how deep in the compilation process.

Notes:
1. I understand that -Wmaybe-uninitialized produces both false positives 
and false negatives.
2. Due to #1 it's difficult to produce a simple test demonstration.
3. I don't want to disable -Wmaybe-uninitialized globally, or for an 
entire function. Warnings are "A Good Thing"(tm).
4. Please, no lectures on why local variables should always be 
initialized at declaration.
5. I now see something similar was requested in 2012 in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55288 but seems to have 
been dismissed with a variation of #4.

Thanks for any info.

-- 
MARK
markrubn@yahoo.com

       reply	other threads:[~2020-10-23 20:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <caf2f32f-3caf-fc89-0ca6-4c885a7b8ff1.ref@yahoo.com>
2020-10-23 20:01 ` mark_at_yahoo [this message]
2020-10-23 20:38   ` Segher Boessenkool
2020-10-23 21:51     ` mark_at_yahoo
2020-10-24  8:49       ` J Decker
2020-10-24 18:32       ` Segher Boessenkool
2020-10-27  8:01         ` mark_at_yahoo
2020-10-24 17:06   ` Florian Weimer
2020-10-24 18:02     ` Segher Boessenkool

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=caf2f32f-3caf-fc89-0ca6-4c885a7b8ff1@yahoo.com \
    --to=markrubn@yahoo.com \
    --cc=gcc-help@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).