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

Avoid some new gcc warnings in 15 #10808

Merged
merged 2 commits into from
Jul 15, 2017

Conversation

TheBlueMatt
Copy link
Contributor

This, plus #10714 avoids adding new compile-time warnings in 15.

Fixes a warning added in #10792.

Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

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

utACK

@meshcollider
Copy link
Contributor

utACK

@achow101
Copy link
Member

utACK a8a602e

src/prevector.h Outdated
prevector() : _size(0) {}
prevector() : _size(0) {
// Explicitly initialize indirect ptr to avoid "used uninitialized" warning
_union.indirect = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

I was vaguely concerned that this assignment violates type punning through a union, but (1) some sources say that is permitted anyway (2) the other type is char (for which exceptions to type punning exist) and (3) we'll write to the union again before ever using data in it.

Copy link
Member

Choose a reason for hiding this comment

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

I though type-punning through an union was the only acceptable way to do it?

Copy link
Member

Choose a reason for hiding this comment

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

From IRC:
sipa: why not use aggregate initialization: prevector() : _size(0), _union{{}}
or give the union a ctor?

I can't reproduce the warning, so I can't be sure that it satisfies whatever compiler is complaining, but the above compiles fine for me, and I'd think that initializing via a ctor would work otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

@laanwj There is a faction of language wonks/compiler folks that argues that it is never acceptable (except with char) per the language specs; -- and I believe there is nothing in any of the C++ standards that make it clear that its kosher (though sipa tells me apparently C11 has something explicit). Since having no way to do it is not a very realistic position it doesn't reflect the behavior of compilers today. Generally better to avoid it at least where its convenient, or at least be aware that someday it might become non-kosher depending on which evil spirits control the souls of the compiler authors next week. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm super not convinced this is an issue. If we're really concerned, easiest fix is probably require C11 and turn prevector into C++ wrapper around C. More realistically, gcc explicitly supports this, and I believe many other compilers as well.

@sipa
Copy link
Member

sipa commented Jul 13, 2017

utACK

@paveljanik
Copy link
Contributor

ACK

Please fix typo in the second commit message (initizlie).

@sipa
Copy link
Member

sipa commented Jul 14, 2017

@theuni's suggestion looks the cleanest to me. Would you mind trying that?

@TheBlueMatt
Copy link
Contributor Author

OK, took @theuni's version (which has no warnings for me).

Warning from gcc 7.1 is ./prevector.h:450:25: warning:
'*((void*)(&<anonymous>)+8).prevector<28, unsigned char>::_union.prevector<28, unsigned char>::direct_or_indirect::<anonymous>.prevector<28, unsigned char>::direct_or_indirect::<unnamed struct>::indirect'
may be used uninitialized in this function [-Wmaybe-uninitialized]
@sipa
Copy link
Member

sipa commented Jul 15, 2017

utACK c73b8be

@sipa sipa merged commit c73b8be into bitcoin:master Jul 15, 2017
sipa added a commit that referenced this pull request Jul 15, 2017
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 6, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 8, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 9, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 11, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 13, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 18, 2019
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
c73b8be Explicitly initialize prevector::_union to avoid new warning (Matt Corallo)
1016dac Fix signed/unsigned comparison warning introduced in c8e29d7. (Matt Corallo)

Tree-SHA512: d1574b0fdc9bfddc3517c382d34418b1d8ed80c81d2f6fd19378c064af8d7704fb84ef8b740ff97f7ec7609bd6de76348921fcc227e1ce97127947a0d22c7887
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants