Hello!
In my humble opinion the -Wreorder has noise. When the order doesn't
matter I would prefer that warnings are not issued.
In this email I include a patch that I would like to get comments
about. The patch will suppress warnings if all members are initialized
with constant values.
I am not very good at GCC internals so I wonder if I made some serious
mistake when using TREE_VALUE, TREE_CODE, etc? Perhaps I overlook
something?
Here is sample code that currently generates warnings but my patch
suppress those warnings:
class Fred {
private:
int a;
int b;
public:
Fred() : b(0), a(0) { }
};
I think the next step will be to suppress the warning if both the
members that the message is about are initialized with constant
values.
Best regards,
Daniel
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (revision 176862)
+++ gcc/cp/init.c (working copy)
@@ -711,6 +711,7 @@
VEC(tree,gc) *vbases;
int i;
int uses_unions_p;
+ int all_inits_are_const; /* all members are initialized with a
constant value */
/* Build up a list of initializations. The TREE_PURPOSE of entry
will be the subobject (a FIELD_DECL or BINFO) to initialize. The
@@ -741,6 +742,25 @@
without issuing a warning. */
next_subobject = sorted_inits;
+ all_inits_are_const = 1;
+ if (warn_reorder)
+ {
+ for (init = mem_inits; init; init = TREE_CHAIN (init))
+ {
+ tree tree_value;
+
+ tree_value = TREE_VALUE(init);
+ if (TREE_CODE(tree_value) == TREE_LIST)
+ tree_value = TREE_VALUE(tree_value);
+
+ if (TREE_CODE(tree_value) != INTEGER_CST)
+ {
+ all_inits_are_const = 0;
+ break;
+ }
+ }
+ }
+
/* Go through the explicit initializers, filling in TREE_PURPOSE in
the SORTED_INITS. */
for (init = mem_inits; init; init = TREE_CHAIN (init))
@@ -762,7 +782,7 @@
/* Issue a warning if the explicit initializer order does not
match that which will actually occur.
??? Are all these on the correct lines? */
- if (warn_reorder && !subobject_init)
+ if (warn_reorder && !all_inits_are_const && !subobject_init)
{
if (TREE_CODE (TREE_PURPOSE (next_subobject)) == FIELD_DECL)
warning (OPT_Wreorder, "%q+D will be initialized after",