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@xxxxxxxxx