There has been a long standing wish to tighten code checking by the compiler by using -Wreorder.
-Wreorder is a compiler switch that checks that the order of declaration of members in the initializer lists of constructors match the order of declaration in the class.
C++ always initializes members in the initializer list in the order of the declaration in the class, it does not matter whether you specify it
differently in the initializer list or not.
An often overseen error is that you accidentally use other members in the initializer list that actually have not been initialized yet, although you did the right ordering in the initializer list.
E.g.
class X {
int b;
int a;
X() : a(5), b(a) {
// actually the content of b is undefined here. As per standard
// your program will always initialize b before a.
}
}
These are somewhat hard to detect errors that might go unnoticed for a while otherwise.
-Wreorder forces you to have b before a in above example in your initializer list by giving a warning otherwise, which causes compilation failure.
This change enables -Wreorder for gcc, clang
-Wreorder is a compiler switch that checks that the order of declaration of members in the initializer lists of constructors match the order of declaration in the class.
C++ always initializes members in the initializer list in the order of the declaration in the class, it does not matter whether you specify it
differently in the initializer list or not.
An often overseen error is that you accidentally use other members in the initializer list that actually have not been initialized yet, although you did the right ordering in the initializer list.
E.g.
class X {
int b;
int a;
X() : a(5), b(a) {
// actually the content of b is undefined here. As per standard
// your program will always initialize b before a.
}
}
These are somewhat hard to detect errors that might go unnoticed for a while otherwise.
-Wreorder forces you to have b before a in above example in your initializer list by giving a warning otherwise, which causes compilation failure.
This change enables -Wreorder for gcc, clang
- is blocked by
-
JDK-8208669 GC changes to allow enabling -Wreorder
-
- Resolved
-
-
JDK-8208670 Compiler changes to allow enabling -Wreorder
-
- Resolved
-
-
JDK-8208671 Runtime, JFR, Serviceability changes to allow enabling -Wreorder
-
- Resolved
-
- relates to
-
JDK-8209193 Fix aarch64-linux compilation after -Wreorder changes
-
- Resolved
-
-
JDK-8209433 [s390] Fix build which was broken by 8208672 (Enable -Wreorder)
-
- Resolved
-
-
JDK-8209132 Enable -Wreorder in make files for MSVC
-
- Open
-
(1 relates to)