This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Wconversion versus libstdc++


On Thu, 18 Jan 2007, Manuel López-Ibáñez wrote:

| On 18/01/07, Gabriel Dos Reis <gdr@cs.tamu.edu> wrote:
| > On Thu, 18 Jan 2007, Manuel López-Ibáñez wrote:
| >
| > | Does that apply also to:
| > |
| > | unsigned int y = -10;
| >
| > Yes.
| >
|
| Then, why Wconversion has warned about it at least since
| http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#SEC11 ?

The description on the page there is:

    Warn if a prototype causes a type conversion that is different
    from what would happen to the same argument in the absence of a
    prototype. This includes conversions of fixed point to floating
    and vice versa, and conversions changing the width or signedness
    of a fixed point argument except when the same as the default
    promotion.

    Also, warn if a negative integer constant expression is implicitly
    converted to an unsigned type. For example, warn about the
    assignment x = -1 if x is unsigned. But do not warn about explicit
    casts like (unsigned) -1.


As the PR you noted, it wasn't part of C++.

[...]

| And my favourite, Gabriel dos Reis willing to implement a warning for
                            ^
Please use capital "D" if you must write my full name; thanks.

| int->unsigned int for g++:
| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26167#c3
|
| :-) I hope you understand why I think the issue is not as clear to me
| as it seems to be for you.

You never re-evaluate based on data collected from experimenting with
applications out there?

Look at the code at issue in libstdc++.  What is wrong with it?
As noted by Joe, such constructs are now likely common place, as they
fall from STL-style view of sequences.  You have to take that into
account.

| Finally, why libstdc++ is using Wconversion at all?

Please go and read the PR submitted by Gerald.

| I don't think it
| is to get warnings about adding prototypes to code, because those
| don't appear in C++, so it can only be to get a warning about unsigned
| int y = -10, since that is the only other documented thing that
| Wconversion did up to GCC 4.3 (which is not even in stage2).
|
| I am still confused, sorry.

I see you're confused :-).

I don't believe in the "only" part of your reasoning.

One use of -Wconversion is to draw attention to

   int x = 2.3;   // warning: be careful, is this what you want?
                  // this is a potential bug as it is value altering.

and in an upcoming revision to C++, it is very likely that implicit
conversion that may lose information are just banned outright, see

   http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n2100.pdf

section "7.1 Can we ban narrowing for T{v}?" on page 27, which
was welcomed at the last C++ committee meeting (at my own surprise, I
must confess, as the committee tends to be conservative).

I suggest to move "int -> unsigned" into a separate category, out of
-Wconversion, if you must keep it.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]