Bug 37854 - No error when creating a variable from itself
Summary: No error when creating a variable from itself
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.3
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-16 16:02 UTC by Julien Sagnard
Modified: 2008-10-21 20:58 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Sagnard 2008-10-16 16:02:20 UTC
If I try to compile this code:

class X {};

int main {
  int i = i;
  X x = x;
  X y(y);
  return 0;
}

With:
gcc -Wall main.cpp

There is no error and no warning.


INFOS:

OS:
Ubuntu Hardy

gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

uname -a
Linux VmWare-Ubuntu 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686 GNU/Linux
Comment 1 Paolo Carlini 2008-10-16 16:16:45 UTC

*** This bug has been marked as a duplicate of 34772 ***
Comment 2 Paolo Carlini 2008-10-16 16:18:56 UTC
Oops, sorry.
Comment 3 Paolo Carlini 2008-10-16 16:22:20 UTC
In mainline (would be 4.4.0), with -Winit-self a warning is emitted for line 4 only. EDG-based compilers apparently do the same...
Comment 4 Andrew Pinski 2008-10-16 19:08:08 UTC
In this case since x and y are empty structs there are no real uses of them.
If I change the code to:
struct X {int i;};

int main()
{
  int i = i;
  X x = x;
  X y(y);
  return i+x.i+y.i;
}
--- CUT ---
And turn on optimization, I get the following warnings:
t.c: In function 'int main()':
t.c:5: warning: 'i' is used uninitialized in this function
t.c:8: warning: 'x.X::i' is used uninitialized in this function
t.c:8: warning: 'y.X::i' is used uninitialized in this function


Note all of the above warnings should only happen with -Winit-self (which works correctly with the C front-end and is PR 34772 ).
Comment 5 Manuel López-Ibáñez 2008-10-21 20:58:36 UTC
Given Andrew's comments, this is not a bug. Thanks for the report nonetheless.