From: miles@gnu.org   
      
   Daniel Krügler writes:   
   >> const int i = fillstack();   
   >> int& i = i;   
   >>   
   >> g++ -Wall –o main main.cpp   
   >> g++ -Wall –O3 –o main main.cpp   
   >> g++ -Wall –g –o main main.cpp   
   >   
   > If a compiler does not diagnose this, you should prepare an enhancement   
   > request for this.   
      
   gcc warns, but only with -Wall (or equivalent), and not directly about   
   this specific issue:   
      
    $ g++ -o m -Wall m.cc   
    m.cc: In function 'int main()':   
    m.cc:10:20: warning: unused variable 'i' [-Wunused-variable]   
    m.cc:13:28: warning: 'i' is used uninitialized in this function   
   [-Wuninitialized]   
      
   I imagine that somebody who doesn't realize what's going on may be   
   confused by those warning messages.   
      
   It seems reasonable to me to have a warning that directly looks for   
   this specific situation (initializing a variable with itself). I   
   imagine intentional uses are very rare, and so such a warning could be   
   enabled by default (no?).   
      
   [Corollary: always use -Wall/-Wextra, or their equivalent in your   
   compiler, unless you're working on a hopelessly crufty old   
   codebase...]   
      
   -Miles   
      
   --   
   Laughter, n. An interior convulsion, producing a distortion of the features   
   and accompanied by inarticulate noises. It is infectious and, though   
   intermittent, incurable.   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|