Boost logo

Boost :

From: Marius Lazer (Marius.Lazer_at_[hidden])
Date: 2007-07-12 17:55:22


Joaquín,

Yes, I forgot the compiler flag when I compiled standalone boost/functional/hash/hash.hpp. Sorry for the confusion.

I can confirm that your analysis is both complete and accurate. We use the highest level of warnings (in the spirit of terseness I omitted all the others like -Wall, etc.) and -Wsign-promo actually found problems so I'd be inclined to keep it.

If someone in the Boost team can guarantee that these warnings are 100% benign (i.e. noise) I can live with them (or just turn -Wsign-promo off for the offending modules), otherwise I'd like to have them fixed.

Thanks for your help,
Marius

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of "JOAQUIN LOPEZ MU?Z"
Sent: Thursday, July 12, 2007 5:29 PM
To: boost_at_[hidden]
Subject: [boost] [hash] GCC warnings with -Wsign-promo (was: multi-indexwarnings)

----- Mensaje original -----
De: Marius Lazer <Marius.Lazer_at_[hidden]>
Fecha: Jueves, Julio 12, 2007 7:22 pm
Asunto: Re: [boost] multi-index warnings
Para: boost_at_[hidden]

> Joaquín,
>
> Here it is (as succinct as I could). All is running on Solaris 10.
>
> Thanks,
> Marius
[...]

Hello Marius,

OK, I've been able to reproduce the problem and after analyzing it
I think that, unless I'm grossly mistaken, the problem lies inside
Boost.Hash --which is not to say this lib has any error, it's just
an effect of this overzealous -Wsign-promo switch. Let me
explain my findings:

I've been able to reproduce the warnings using exclusively
Boost.Hash:

***code1***
// warns with Boost 1.34, clean compile with Boost 1.31
#include <boost/functional/hash/hash.hpp>

int main(){}
***code1***

This warns with Boost 1.34 and does not warn wih Boost 1.33.1,
under GCC 3.4.4 for Cygwin, always using the -Wsign-promo switch.
This is in contradiction with some previous reports by you, my
guess is that you forgot to include the switch (could you confirm
this?) According to GCC docs, -Wsign-promo "warn[s] when
overload resolution chooses a promotion from unsigned or enumeral
type to a signed type over a conversion to an unsigned type of
the same size.[...]" The relevant portion of Boost 1.34
Boost.Hash can be isolated and simplified to more easily show
the issue:

***code2***
#include <cstddef>

std::size_t hash_value(int){return 0;}
std::size_t hash_value(long int){return 0;}

template<typename> struct hash;

template<> struct hash<bool>
{
  std::size_t operator()(bool x)const{return hash_value(x);}
};

int main(){}
***code2***

This emits the same kind of warnings you've seen: -Wsign-promo
informs about the int overload having been chosen in preference
to the long int overload (you can try yourself).

As for why Boost.Hash 1.33.1 does not produce warnings, the
reason is that in Boost 1.33.1 hash<T> is defined (roughly)
as:

template<typename> struct hash
{
  std::size_t operator()(T x)const{return hash_value(t);}
};

whereas in Boost 1.34 the class template hash is left
undefined and a number of full specializations (like
bool and other integral types) are explicitly defined,
in the spirit of the code2 snippet. Matter of fact, the
following will emit the warnings *both* with Boost 1.33.1
and 1.34:

***code3***
// warns with Boost 1.33.1 and 1.34
#include <boost/functional/hash/hash.hpp>

int main()
{
  boost::hash<bool> h;
  h(true);
}
***code3***

Again, I'd be grateful if you can confirm all of this in
your own environment.

What to do about this? Of course if you can skip the
-Wsign-promo switch no warnings will arise. If this is not an
option, the author of Boost.Hash should have to be convinced
to fix this, possibly by providing more overloads of
hash_value (for bool and the rest of offending types) so
as to avoid integral promotions altogether.

Hope this helps, please come back if your experiments
do not agree with this analysis.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

**********************************************************************
This communication and all information (including, but not limited to,
 market prices/levels and data) contained therein (the "Information") is
 for informational purposes only, is confidential, may be legally
 privileged and is the intellectual property of ICAP plc and its affiliates
 ("ICAP") or third parties. No confidentiality or privilege is waived or
 lost by any mistransmission. The Information is not, and should not
 be construed as, an offer, bid or solicitation in relation to any
 financial instrument or as an official confirmation of any transaction.
 The Information is not warranted, including, but not limited, as to
 completeness, timeliness or accuracy and is subject to change
 without notice. ICAP assumes no liability for use or misuse of the
 Information. All representations and warranties are expressly
 disclaimed. The Information does not necessarily reflect the views of
 ICAP. Access to the Information by anyone else other than the
 recipient is unauthorized and any disclosure, copying, distribution or
 any action taken or omitted to be taken in reliance on it is prohibited. If
 you receive this message in error, please immediately delete it and all
 copies of it from your system, destroy any hard copies of it and
 notify the sender.
**********************************************************************


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk