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,540 of 33,346    |
|    =?windows-1252?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Validity of decltype(main())    |
|    17 Sep 12 07:12:21    |
   
   From: daniel.kruegler@googlemail.com   
      
   Am 17.09.2012 06:26, schrieb Gido:   
   > Is the following valid C++:   
   >   
   > int main() {   
   > decltype(main()) i;   
   > }   
   >   
   > Is this guaranteed to resolve to "int i"?   
      
   I don't think so.   
      
   > I believe in general you can state decltype(function()) and it will   
   > yield the return type of the function. I am unsure because of   
   > main(); special rules might apply.   
   >   
   > 3.6.1.3 states "The function main shall not be used within a   
   > program". But since the appearance in a decltype operand is not   
   > "usage", I would guess the code in the example above is correct.   
      
   Note that C++11 invented the term "odr-usage" as a significant   
   difference to "usage". The term "use" has no longer any special   
   meaning in the C++ Standard, so I would consider that by writing   
      
   decltype(main())   
      
   you are indeed "using" function main in the normal meaning of the   
   English language.   
      
   > GCC (4.7.0) with -pedantic however complains: "ISO C++ forbids   
   > taking address of function ‘::main’". This has me doubting the code.   
      
   While the diagnostics is very misleading, the error seems appropriate   
   to me.   
      
   HTH & 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