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

Remove 'boost::optional'-related false positive -Wmaybe-uninitialized warnings on GCC compiler #15292

Merged
merged 1 commit into from Jan 30, 2019

Conversation

Projects
None yet
9 participants
@hebasto
Copy link
Member

commented Jan 30, 2019

#14711 introduced some warnings when building with gcc compiler.

See:

This gcc issue has been known since version 4.6.0 and last updated in 2017.
From the boost docs:

The default constructor of optional creates an uninitialized optional object.

Also: False positive with -Wmaybe-uninitialized (pointed out by @Empact)

This PR removes these warnings.

cc: @Empact @practicalswift

@hebasto hebasto force-pushed the hebasto:20190130-gcc-maybeuninitialized branch from a1d9961 to 595b62f Jan 30, 2019

@DrahtBot

This comment has been minimized.

Copy link
Contributor

commented Jan 30, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

Generally we don't work around bugs in a compiler if they are only warning related and fixed in recent versions.

@hebasto

This comment has been minimized.

Copy link
Member Author

commented Jan 30, 2019

@MarcoFalke

Generally we don't work around bugs in a compiler if they are only warning related and fixed in recent versions.

Which recent version of gcc do you mean?

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

According to the bug report, it was fixed in gcc6. I am using clang7.

@ryanofsky

This comment has been minimized.

Copy link
Contributor

commented Jan 30, 2019

I would prefer not to make these changes since I think they make the code less readable, are only applicable to older buggy versions of gcc, and just avoid warnings not errors.

But I will add my utACK 595b62f since the changes do look safe, and other people might want them.

I wonder what would happen if you tried to replace:

Optional<int> height;

with:

Optional<int> height = nullopt;

I think a change like that would be more readable.

@hebasto

This comment has been minimized.

Copy link
Member Author

commented Jan 30, 2019

@MarcoFalke

According to the bug report, it was fixed in gcc6. I am using clang7.

I am using gcc 7.3.0 (both Linux Mint 19.1 and Ubuntu Bionic). Warnings are still present.

@ryanofsky

Optional<int> height = nullopt;

I've tried this approach while working on this PR. nullopt did not help. Perhaps this is due to the lazy initialization inside boost::optional.

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

gcc8 will also spit out a false positive warning, since it can not infer that either none or both of altheight and height are initialized. Not sure if this should be fixed or how.

@Empact

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

I think "The default constructor of optional creates an uninitialized optional object." may be misleading as default-constructed values are valid, e.g.. boost::optional has an is_initialized member that is false on default initialization, and just means the object is falsey.

Other thoughts:
I would prefer not to use auto here given there are plenty of numeric types.
I would access this functionality via src/optional.h, where the other boost::optional references are.

Incidentally here's the doc where boost recommends this fix.
No opinion on whether this should be fixed.

@hebasto

This comment has been minimized.

Copy link
Member Author

commented Jan 30, 2019

@Empact TIL. Thank you.

@hebasto hebasto force-pushed the hebasto:20190130-gcc-maybeuninitialized branch from 595b62f to c14d580 Jan 30, 2019

@hebasto

This comment has been minimized.

Copy link
Member Author

commented Jan 30, 2019

@Empact your comment has been addressed.

@hebasto hebasto changed the title Remove 'boost::optional'-related gcc warnings Remove 'boost::optional'-related false positive -Wmaybe-uninitialized warnings on GCC compiler Jan 30, 2019

@laanwj

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

I'm using gcc 7.3.0 on my main development system so I see these scary warnings all the time, so I'd prefer for this to be merged or the relevant warning disabled (for that gcc).

Edit: tested that this makes the warnings disappear here.

@@ -41,6 +41,8 @@

#include <functional>

#include <boost/optional.hpp>

This comment has been minimized.

Copy link
@laanwj

laanwj Jan 30, 2019

Member

I'd mildly prefer to redirect this through our optional.h, define our own make_optional like the Option<T> itself instead of boost appearing here direclty.

@gmaxwell

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

Found this PR after seeing the scary warnings... maybe-uninitialized is a pretty potent warning, I wouldn't want to disable it unless it was only on old compilers.

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

Hmm, one of the warnings disappears when going from gcc7 to gcc8?

@practicalswift

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

utACK c14d580 modulo @laanwj's nit regarding optional.h

@hebasto hebasto force-pushed the hebasto:20190130-gcc-maybeuninitialized branch from c14d580 to 2d48314 Jan 30, 2019

@hebasto

This comment has been minimized.

Copy link
Member Author

commented Jan 30, 2019

@laanwj's nit has been addressed.

@practicalswift

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

utACK 2d48314

1 similar comment
@laanwj

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

utACK 2d48314

@Empact

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

utACK 2d48314

@laanwj laanwj merged commit 2d48314 into bitcoin:master Jan 30, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

laanwj added a commit that referenced this pull request Jan 30, 2019

Merge #15292: Remove 'boost::optional'-related false positive -Wmaybe…
…-uninitialized warnings on GCC compiler

2d48314 Remove 'boost::optional'-related gcc warnings (Hennadii Stepanov)

Pull request description:

  #14711 introduced some warnings when building with gcc compiler.

  See:
  - #14711 (comment) by @laanwj
  - #14711 (review) by @ryanofsky

  This gcc [issue](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47679) has been known since version 4.6.0 and last updated in 2017.
  From the boost [docs](https://www.boost.org/doc/libs/1_69_0/libs/optional/doc/html/boost_optional/quick_start/optional_automatic_variables.html):
  > The default constructor of `optional` creates an _uninitialized_ `optional` object.

  Also: [False positive with -Wmaybe-uninitialized](https://www.boost.org/doc/libs/1_69_0/libs/optional/doc/html/boost_optional/tutorial/gotchas/false_positive_with__wmaybe_uninitialized.html) ([pointed out](#15292 (comment)) by @Empact)

  This PR removes these warnings.

  cc: @Empact @practicalswift

Tree-SHA512: 752ae3c3ca6282bbf98726236fbc3069ab9d1aee57ae2ec2668b32e4541e7bc1acb15b7d6fa9e2b6daf1ec29c0987a1053ee1ca0f523b71367ff911221c58c94

@hebasto hebasto deleted the hebasto:20190130-gcc-maybeuninitialized branch Jan 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.