Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,551 of 33,346    |
|    =?windows-1252?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Initializing a shadowing variable wi    |
|    20 Sep 12 12:24:58    |
   
   From: daniel.kruegler@googlemail.com   
      
   { Please limit your quoting to the minimum needed to establish context   
   -mod }   
      
   Am 20.09.2012 20:36, schrieb Richard Damon:   
   > On 9/20/12 12:26 AM, Daniel Krügler wrote:   
   >>   
   >> I strongly hope CWG 504 gets to be resolved such that the language   
   >> would forbid the initialization of a variable with its own value   
   >> (Note that valid cases of seemingly self-initialization e.g. a   
   >> pointer initialized with the address of the variable should still   
   >> be allowed).   
   >>   
   >> HTH & Greetings from Bremen,   
   >>   
   >> Daniel Krügler   
   >>   
   >>   
   >>   
   >   
   > The problem is that there are cases where it is impossible to tell   
   > without looking at the whole program.   
   >   
   > Take the example:   
   >   
   > extern void foo(int& i);   
   >   
   > extern int x;   
   >   
   > void bar(){   
   > int x = (foo(x), x);   
   > }   
   >   
   > Is x inside of bar being self-initialized? Until you know what is   
   > inside foo you can not tell. foo might initialize its parameter, or   
   > it might not, and the code for foo might not be in the same   
   > translation unit.   
      
   Sure, but I don't think that this example is compelling enough to be   
   captured by a fix of CWG 504. I think it would be sufficient to   
   specify a rule that make code ill-formed that would attempt to   
   "directly initialize" (with a proper definition therefore) a variable   
   by itself.   
      
   > It is in the tradition of C/C++ to not require the compiler to dig   
   > that hard to figure out if something is wrong. (but it is perfectly   
   > ok for the compiler to do what it can to give a warning about   
   > this). Because it would be impossible to come up with wording that   
   > would disallow all cases, and that reasonably simple wordings will   
   > tend to disallow cases that might really be valid and possibly   
   > useful, the Standard does its normal thing and requires the   
   > programmer to use some minimal care to keep from shooting themselves   
   > in their foot.   
      
   Certainly true, but a rule could still be helpful if it would capture   
   the simple cases.   
      
   Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
   --   
    [ 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)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca