Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearrange initialiser lists so we can use -Werror=reorder #28165

Merged
merged 32 commits into from
Sep 24, 2024

Conversation

peterbarker
Copy link
Contributor

-Werror=reorder enforces a rule that initalisers must appear in the same order as the members they are initialising appear in the class declaration.

Having these appear in the wrong order can lead to programmers believing one thing about the order of object construction when something else is happening.

See point 3 from: https://en.cppreference.com/w/cpp/language/constructor

Initialization order

The order of member initializers in the list is irrelevant: the actual order of initialization is as follows:
1) If the constructor is for the most-derived class, virtual bases are initialized in the order in which they appear in depth-first left-to-right traversal of the base class declarations (left-to-right refers to the appearance in base-specifier lists).
2) Then, direct bases are initialized in left-to-right order as they appear in this class's base-specifier list.
3) Then, non-static data member are initialized in order of declaration in the class definition.
4) Finally, the body of the constructor is executed.

These patches are pulled out of a larger PR as they are completely no-compiler-output-change:

Board                    AP_Periph  blimp  bootloader  copter  heli  iofirmware  plane  rover  sub
CubeOrange-periph-heavy  *                                                                     
Durandal                            *      *           *       *                 *      *      *
Hitec-Airspeed           *                                                                     
KakuteH7-bdshot                     *      *           *       *                 *      *      *
MatekF405                           *      *           *       *                 *      *      *
Pixhawk1-1M-bdshot                  *                  *       *                 *      *      *
f103-QiotekPeriph        *                                                                     
f303-Universal           *                                                                     
iomcu                                                                *                         
revo-mini                           *      *           *       *                 *      *      *
skyviper-v2450                                         *                                       

@peterbarker peterbarker force-pushed the pr/reorder-simple-stuff branch 3 times, most recently from 4ec144c to 35b08c2 Compare September 22, 2024 05:50
Copy link
Contributor

@tpwrules tpwrules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked through all of these and nothing raises immediate concern that an initialization order was wrong.

I agree that we can remove blah() in most cases as in the member initializer list that is identical in behavior to T blah; in the class definition so long as T is a class type. If T is not, then we need to keep it.

libraries/AP_HAL/HAL.h Outdated Show resolved Hide resolved
@peterbarker peterbarker merged commit 24df6f1 into ArduPilot:master Sep 24, 2024
95 checks passed
@peterbarker peterbarker deleted the pr/reorder-simple-stuff branch September 26, 2024 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants