-
Notifications
You must be signed in to change notification settings - Fork 36.2k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
utACK |
utACK a8a602e |
src/prevector.h
Outdated
prevector() : _size(0) {} | ||
prevector() : _size(0) { | ||
// Explicitly initialize indirect ptr to avoid "used uninitialized" warning | ||
_union.indirect = nullptr; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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.
utACK |
ACK Please fix typo in the second commit message (initizlie). |
@theuni's suggestion looks the cleanest to me. Would you mind trying that? |
a8a602e
to
a0f6bf9
Compare
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]
a0f6bf9
to
c73b8be
Compare
utACK c73b8be |
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
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
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
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
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
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
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
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
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
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
This, plus #10714 avoids adding new compile-time warnings in 15.
Fixes a warning added in #10792.