#1977 Passing a function with a reference

OTHER
open
nobody
g++ (23)
Support
none
component_package
False
2013-05-29
2013-05-29
Pavel
No
Hello!
//---------------------- compile error !!!!!!!!! --------------------------
template <typename... _Arg>
    void sub_fn_wraper(void(*fun)(_Arg...), _Arg... arg)
    {
        return (*fun)(arg...);
    }

template <typename F = void>
     void sub_fn(int&) {}

void fn()
{
    int val(0);
    sub_fn_wraper<int&>(sub_fn, val);
}

int main()   { fn(); }
//---------------------- Ok !!!!!!!!! --------------------------
//template <typename... _Arg>
//    void sub_fn_wraper(void(*fun)(_Arg...), _Arg... arg)
//    {
//        return (*fun)(arg...);
//    }
//
//template <typename F = void>
//     void sub_fn(int) {}   // not reference
//
//void fn()
//{
//    int val(0);
//    sub_fn_wraper<int>(sub_fn, val);   // not reference
//}
//
//int main()   { fn(); }
//---------------------- Ok !!!!!!!!! --------------------------
//template <typename... _Arg>
//    void sub_fn_wraper(void(*fun)(_Arg...), _Arg... arg)
//    {
//        return (*fun)(arg...);
//    }
//
////template <typename F = void>   // commented
//     void sub_fn(int&) {}
//
//void fn()
//{
//    int val(0);
//    sub_fn_wraper<int&>(sub_fn, val);
//}
//
//int main()   { fn(); }
//---------------------- Ok !!!!!!!!! --------------------------
//template <typename _Arg>   // not variadic
//    void sub_fn_wraper(void(*fun)(_Arg), _Arg arg)
//    {
//        return (*fun)(arg);
//    }
//
//template <typename F = void>
//     void sub_fn(int&) {}
//
//void fn()
//{
//    int val(0);
//    sub_fn_wraper<int&>(sub_fn, val);
//}
//
//int main()   { fn(); }

Discussion

  • Pavel

    Pavel - 2013-05-29

    Windows 7, x64

    gcc -v
    Using built-in specs.
    COLLECT_GCC=C:\MinGW\bin\gcc.exe
    COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe
    Target: mingw32
    Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,obj
    c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
    mp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-
    with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
    Thread model: win32
    gcc version 4.7.2 (GCC)

    ld -v
    GNU ld (GNU Binutils) 2.23.1

    MinGW Version
    3.20

    MSYS shell
    uname -a
    MINGW32_NT-6.1 ПАХА-ПК 1.0.18(0.48/3/2) 2012-11-21 22:34 i686 Msys

     
  • Pavel

    Pavel - 2013-05-29

    Compiler - g++

     
  • Earnie Boyd

    Earnie Boyd - 2013-05-29
    • labels: --> g++
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,5 +1,6 @@
         Hello!
    
    +~~~~~
     //---------------------- compile error !!!!!!!!! --------------------------
     template <typename... _Arg>
         void sub_fn_wraper(void(*fun)(_Arg...), _Arg... arg)
    @@ -17,9 +18,9 @@
     }
    
     int main()   { fn(); }
    +~~~~~
    
    -
    -
    +~~~~~
     //---------------------- Ok !!!!!!!!! --------------------------
     //template <typename... _Arg>
     //    void sub_fn_wraper(void(*fun)(_Arg...), _Arg... arg)
    @@ -37,8 +38,9 @@
     //}
     //
     //int main()   { fn(); }
    +~~~~~
    
    -
    +~~~~~
     //---------------------- Ok !!!!!!!!! --------------------------
     //template <typename... _Arg>
     //    void sub_fn_wraper(void(*fun)(_Arg...), _Arg... arg)
    @@ -56,8 +58,9 @@
     //}
     //
     //int main()   { fn(); }
    +~~~~~
    
    -
    +~~~~~
     //---------------------- Ok !!!!!!!!! --------------------------
     //template <typename _Arg>   // not variadic
     //    void sub_fn_wraper(void(*fun)(_Arg), _Arg arg)
    @@ -75,3 +78,4 @@
     //}
     //
     //int main()   { fn(); }
    +~~~~~
    
    • status: unread --> open
    • Type: Bug --> Support
    • Category: Unknown --> component_package
     
  • Earnie Boyd

    Earnie Boyd - 2013-05-29

    Pavel, you need to discuss this with gcc.gnu.org.

     
  • Pavel

    Pavel - 2013-05-29

    But I don't know if there is a bug in the latest version of GCC.

     
  • Earnie Boyd

    Earnie Boyd - 2013-05-29

    Then please discuss it on mingw-users list.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks