c++ - use of a static constexpr member function returning auto inside class -


i'm trying workaround bug in msvc 2015 encountered (see question : wrong type deduction of function signature).

so came :

#include<windows.h>  namespace wreg {  using t_oshandle     = hkey;  struct t_api {     static constexpr      auto fnc_open_key ()     { return ::regopenkeyexa; }      //this doesn't compile :     static constexpr auto open_key   = fnc_open_key();      //these don't compile either:     //static constexpr decltype(fnc_open_key()) open_key     = fnc_open_key();     //static constexpr decltype(::regopenkeyexa) open_key    = fnc_open_key(); };  //this compiles , runs : constexpr auto open_key  = t_api::fnc_open_key();  } // namespace wreg   //int main( int argc ,_tchar* argv[] ); {     auto     hk = wreg::t_oshandle{};     auto     res = wreg::t_api::open_key( hkey_local_machine ,"software" ,0 ,key_read ,&hk );     //auto   res = wreg::open_key( hkey_local_machine ,"software" ,0 ,key_read ,&hk );      if (res == error_success)     {         res = ::regclosekey( hk );     }     return 0; } 

but doesn't compile because of

error c3779: 'wreg::t_api::fnc_open_key': function returns 'auto' cannot used before defined

i don't that. it's defined @ point use it. , besides ,within class usually names local class definition can use before definition/declaration.

question : why msvc right or should code compile ?

you can try use decltype on auto function deduction:

auto fnc_open_key () -> decltype(::regopenkeyexa) {        return ::regopenkeyexa; } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -