https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91952
Bug ID: 91952
Summary: [rfe] __attribute__((__default_value__()))
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: allison.karlitskaya at redhat dot com
Target Milestone: ---
In automatic context, instead of writing
int x = 5;
it would be nice to be able to write
__attribute__((__default_value__(5))) int x;
which would have slightly different semantics: the default value would be
required to be a compile-time constant, and the variable would always have the
initial value, as soon as it is allocated, even if the declaration is never
reached (for example, in case the line is skipped with a 'goto'). See bug
91951 about that.
This would also allow for a longstanding improvement in some glib macro hackery
that is in wide use: g_autoptr(). Currently you need to write:
g_autoptr(GObject) my_object = NULL;
in order to insure that GCC doesn't call the cleanup function on a random
pointer value. It wasn't possible to absorb the = NULL into the macro in a way
that didn't make the variable declaration look like a function call. If
something like __attribute__((__default_value__)) had been available at the
time, I would have surely used it.
Can we add it now?