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

Bug#461789: Confusing error about uninitialized values.



Package: g++-4.3
Version: 4.3-20080116-1
Severity: minor

  Obviously we want our compilers to be smart, but I think g++-4.3 is
too smart for me. ;-)

  In the attached file, compiling with -Wall and -O2 produces a warning:

foo.cc: In function ‘int main(int, char**)’:
foo.cc:30: warning: ‘tmp.foo::real_foo’ is used uninitialized in this function
foo.cc:36: note: ‘tmp.foo::real_foo’ was declared here

  This is rather confusing, since lines 30 and 36 aren't even in the
same function!  The code looks right to me, but I'm willing to believe
that there's a subtle problem I don't see.  g++ needs to report it in a
more obvious way, though.  (of course, it could be an outright bug in
g++, but that seems like a slim possibility)

  I've seen this problem twice now, both times in the destructor of a
smart pointer class.  But the same classes are used without any trouble
in lots of other places in my code, so I'm not quite sure what's going
on.  Maybe I just get lucky everywhere else?

  Daniel

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.22-3-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to en_US.UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages g++-4.3 depends on:
ii  gcc-4.3                   4.3-20080116-1 The GNU C compiler
ii  gcc-4.3-base              4.3-20080116-1 The GNU Compiler Collection (base 
ii  libc6                     2.7-6          GNU C Library: Shared libraries
ii  libgmp3c2                 2:4.2.2+dfsg-1 Multiprecision arithmetic library
ii  libmpfr1ldbl              2.3.0.dfsg.1-2 multiple precision floating-point 
ii  libstdc++6-4.3-dev        4.3-20080116-1 The GNU Standard C++ Library v3 (d

g++-4.3 recommends no packages.

-- no debconf information

#include <string>

class foo
{
  class impl;

  impl *real_foo;
  foo();
public:
  foo(const std::string &prefix);
  ~foo();
};

class foo::impl
{
public:
  impl();
  ~impl();

  void bar();
};

inline foo::foo(const std::string &prefix)
  : real_foo(new impl)
{
}

inline foo::~foo()
{
  real_foo->bar();
}


int main(int argc, char **argv)
{
  foo tmp("foo");

  return 0;
}


Reply to: