home bbs files messages ]

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,538 of 33,346   
   Gido to All   
   Validity of decltype(main())   
   16 Sep 12 21:26:51   
   
   From: gido0001@googlemail.com   
      
   Is the following valid C++:   
      
   int main() {   
        decltype(main()) i;   
   }   
      
   Is this guaranteed to resolve to "int i"?   
      
   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.   
      
   GCC (4.7.0) with -pedantic however complains: "ISO C++ forbids taking   
   address of function ‘::main’". This has me doubting the code.   
      
   Similarly, what about decltype(main)? I am quite sure that due to   
   3.6.1.2 "It [global main, red] shall have a return type of type int,   
   but otherwise its type is implementation-defined" the result of this   
   is implementation-defined at best, but is it valid?   
      
   (Of course I know the example code is awful; the question is purely   
   out of interest.)   
      
   Thanks.   
      
      
   --   
         [ 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