Re: Use an undefined variable

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

 



> There is an unbounded number of incorrect C++ programs.  We warn about
>  a subset of them.  Detecting every incorrect C++ program is, I'm sure
>  an uncomputable problem.
>

The -Wuninitialized and -Winit-self options are meant to check exactly
this kind of incorrect programs, and I'm quite disappointed that the
following function

template<class T> T f(T x)
{
    T y = x + y;
    return y;
}

generates a warning when instantiated with T = int, but not when T =
std::string.

Furthermore, my impression is that the use of an uninitialized integer
is "less incorrect" than the use of a complex object before even
calling its constructor. Several rules of the C++ language are meant
to guarantee that all objects are constructed (exactly once) before
their use, and destructed (exactly once) when they go out of scope.

   Dario

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux