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

Fix deprecated copies and redundant moves #1950

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

mcm001
Copy link
Contributor

@mcm001 mcm001 commented Dec 29, 2024

While working on wpilibsuite/allwpilib#7606 I had to disable deprecated copy and redundant move warnings. I'm not super great with this aspect of C++, but I've added default constructors where they were previously implicitly declared.

@varunagrawal
Copy link
Collaborator

Doesn't C++ automatically add these if they're not defined? I may be wrong though.

@mcm001
Copy link
Contributor Author

mcm001 commented Dec 29, 2024

Yes, but if you have deprecated copy warnings enabled they'll reported warnings. I'm trying to find a primary source, but per gcc's bugzilla,

"The implicit definition of a copy constructor as defaulted is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor. The implicit definition of a copy assignment operator as defaulted is deprecated if the class has a user-declared copy constructor or a user-declared destructor"

TLDR: compile with -Wdeprecated-copy and observe compiler output

@mcm001
Copy link
Contributor Author

mcm001 commented Dec 29, 2024

Although this might be worth a larger discussion. What warnings does GTSAM currently compile with? Is there any interest in enabling more compiler warnings/enabling Werror?

@mcm001 mcm001 force-pushed the deprecated-copy-redundant-move branch 2 times, most recently from f7aecd8 to 846c29f Compare December 30, 2024 00:10
@varunagrawal
Copy link
Collaborator

Okay I'm going to need your help understanding this better. I currently don't get these warnings so is it a result of a newer version of GCC?

In general we ignore warnings since most of the time they don't reflect a real problem. I'm curious if suppressing these warnings are sufficient in your use case?

My guiding philosophy here is less code is good code.

@dellaert
Copy link
Member

dellaert commented Jan 2, 2025

In general we ignore warnings since most of the time they don't reflect a real problem. I'm curious if suppressing these warnings are sufficient in your use case?

Disagree. If we can -Wall so much the better!

My guiding philosophy here is less code is good code.

Totally agree here, but I have a suspicion that this extra code might actually benefit performance even for other compilers? any idea, @mcm001 ?

@mcm001
Copy link
Contributor Author

mcm001 commented Jan 2, 2025

Hey! At least in some Godbolt testing, I don't see a meaningful difference in the actual binary output of this contrived test program with GCC 12.2 on x86 or arm64. I think this just comes down to if y'all are in favor of fixing warnings even if the code output is (probably) correct. I think that fixing rule-of-3/5/0-related warnings is a good idea, and deleting redundant moves also lets us write less code ;)

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

I’m in favor of -Wall so approving. We should probably add a gcc12 CI, maybe instead of gcc11. Not sure whether gcc9 is already EOL?

@mcm001
Copy link
Contributor Author

mcm001 commented Jan 2, 2025

I've also got a tiny patchset that lets me build with -Wall -Wpedantic on GCC 12, should be ready here in a moment. Happy to add that in a follow-on PR, or add to this one

@mcm001
Copy link
Contributor Author

mcm001 commented Jan 2, 2025

And from https://gcc.gnu.org/gcc-9/ and https://gcc.gnu.org/gcc-10/ , it appears GCC 9/10 are EOL yeah

@dellaert
Copy link
Member

dellaert commented Jan 2, 2025

Awesome ! Maybe do it in a follow-up PR where you also switch 11 to 12 in CI?
I know some folks were using gcc9 on some embedded platforms but maybe we could switch that to 10…

@dellaert dellaert changed the title Fix deperecated copies and redundant moves Fix deprecated copies and redundant moves Jan 2, 2025
@mcm001
Copy link
Contributor Author

mcm001 commented Jan 2, 2025

Sounds good! Will add in a follow-on

@dellaert dellaert merged commit c2a1242 into borglab:develop Jan 2, 2025
33 checks passed
dellaert added a commit that referenced this pull request Jan 2, 2025
Fix deprecated copies and redundant moves
@mcm001 mcm001 deleted the deprecated-copy-redundant-move branch January 2, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants