libgolang: Fix double C++ defer
If defer was used multiple times in one function it was failing to compile. For example added test is failing like this: In file included from golang/runtime/libgolang_test.cpp:22: golang/runtime/libgolang_test.cpp: In function ‘void __test_defer(int*)’: ./golang/libgolang.h:457:59: error: redeclaration of ‘golang::_deferred _defer___COUNTER__’ #define defer(f) golang::_deferred _defer_ ## __COUNTER__ (f) ^ golang/runtime/libgolang_test.cpp:473:5: note: in expansion of macro ‘defer’ defer([&]() { ^~~~~ ./golang/libgolang.h:457:36: note: ‘golang::_deferred _defer___COUNTER__’ previously declared here #define defer(f) golang::_deferred _defer_ ## __COUNTER__ (f) ^~~~~~~ golang/runtime/libgolang_test.cpp:470:5: note: in expansion of macro ‘defer’ defer([&]() { ^~~~~ It turns out the __COUNTER__ was not expanded and they say you have to use 3 level of macro calls. Oh well... https://stackoverflow.com/a/27611869/9456786
Showing
Please register or sign in to comment