Avoid some new gcc warnings in 15 #10808

Merged
merged 2 commits into from Jul 15, 2017

Conversation

Projects
None yet
9 participants
Contributor

TheBlueMatt commented Jul 12, 2017

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

Fixes a warning added in #10792.

@gmaxwell

utACK

utACK

Contributor

achow101 commented Jul 12, 2017

utACK a8a602e

src/prevector.h
- prevector() : _size(0) {}
+ prevector() : _size(0) {
+ // Explicitly initialize indirect ptr to avoid "used uninitialized" warning
+ _union.indirect = nullptr;
@sipa

sipa Jul 13, 2017

Owner

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.

@laanwj

laanwj Jul 13, 2017

Owner

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

@theuni

theuni Jul 13, 2017

Member

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.

@gmaxwell

gmaxwell Jul 13, 2017

Member

@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. :)

@TheBlueMatt

TheBlueMatt Jul 14, 2017

Contributor

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.

Owner

sipa commented Jul 13, 2017

utACK

Contributor

paveljanik commented Jul 13, 2017

ACK

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

Owner

sipa commented Jul 14, 2017 edited

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

Contributor

TheBlueMatt commented Jul 14, 2017

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

@TheBlueMatt TheBlueMatt Explicitly initialize prevector::_union to avoid new warning
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]
c73b8be
Owner

sipa commented Jul 15, 2017

utACK c73b8be

@sipa sipa merged commit c73b8be into bitcoin:master Jul 15, 2017

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@sipa sipa added a commit that referenced this pull request Jul 15, 2017

@sipa sipa Merge #10808: Avoid some new gcc warnings in 15
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
ec8a50b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment