[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#119440: g++: Compiler does not give any errors when a function fails to return required value



On Wed, Nov 14, 2001 at 02:24:16PM +0200, Eray Ozkural (exa) wrote:
> Not exactly. Here is what I'm talking about:
[...]
> int f(int x)
> {
>    int f;
>    f = 2;
>    for (int i=1; i<=4; i++) {
>       f = f + i * x;
>    }
> }
[...]
> It 
> might be valid in C++ specification (is it?), but the compiler should warn 
> about it.

Undefined behavior, which means that no requirements are placed on the
compiler.  More specifically:

#    permissible undefined behavior ranges from ignoring the situation
#    completely with unpredictable results, to behaving during translation
#    or program execution in a documented manner characteristic of the
#    environment (with or without the issuance of a diagnostic message),
#    to terminating a translation or execution (with the issuance of a
#    diagnostic message).

So the compiler is compliant in this regard, and there is no bug.  (This is
the infamous "it's free to format your hard drive if it wants to, or it
could do exactly what you hope it would" clause.)

Now, I agree with you that the "bug" if there is one is in the standard
itself; the language requirement should IMO be tightened.  However, that's
a definite "wishlist" item far beyond the scope of this mailing list.
The next meeting of the C++ standards committee is in April; if you'd like
to hop over to the Netherlands and submit this as a bug.  :-)

Alternatively, the Debian build of GCC could enable a stricter set of
warnings by default.  But that's also a wishlist item, and that carries its
own problems.  (Reproducing warnings on a non-Debian system, for example,
becomes an act of mind-reading.)


Ah crumbs, I'm sending something to an @bugs address again.  Here come
the notification messages, whee...

Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



Reply to: