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 Wed, 17 Jan 2007, Andrew Pinski wrote:

| >
| > 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).
|
| The union between C and C++,

well, as C++ is adding more stuff, the union can only grow, not shrink :-)
I suspect you meant the intersection.

Did you read the reference?  You'll see that the ban is only for
aggregate-style initialization, as in

   char x = { 2879 };

| just became smaller and I don't think C++ should be named C++ anymore then.

you seem to know better what is C++ than its designer.  Good for you.

In case, you want to know how and why implicit conversions came into
C, you might probably want to read section "7.1.2 Why do we have the
narrowing problem?"

  # Some implicit casts, such as double->int and int->char, have
  # traditionally been consider a significant  even invaluable
  # notational convenience. Others, such as double->char and int*->bool,
  # are widely considered embarrassments. When Bjarne once asked around
  # in the Unix room why implicit narrowing had actually been
  # allowed. Nobody argued that there were a fundamental technical
  # reason, someone pointed out the obvious potential for errors and all
  # agreed that the reason was simply historical: Dennis Ritchie added
  # floating point before Steve Johnson added casts. Thus, the use of
  # implicit narrowing was well established before explicit casting
  # became an option.
  #
  # Bjarne tried to ban implicit narrowing in C with Classes but found
  # that a combination of existing practice (especially relating to the
  # use of chars) and existing code made that infeasible. Cfront,
  # however, stamped out the double->int conversions for early
  # generations of C++ programmers by providing long, ugly, and
  # non-suppressible warnings.
  #
  # Please note that the suggestion to ban narrowing does not actually
  # touch these common examples. It relies on explicit use of { }.

-- Gaby


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