TheNitesWhoSay / RareCpp

Creating a simpler, more intuitive means of C++ reflection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compile failed in ubuntu-18.04

kongdd opened this issue · comments

I am trying to use Reflect.h in R (https://github.com/kongdd/hello.R/blob/master/src/test-reflect.cpp). However, failed in ubuntu-18.04.
Any idea how to solve this issue?

https://github.com/kongdd/hello.R/runs/5064647738?check_suite_focus=true

g++ -std=gnu++17 -I"/opt/R/4.1.2/lib/R/include" -DNDEBUG  -I'/home/runner/work/_temp/Library/Rcpp/include' -I'/home/runner/work/_temp/Library/RcppArmadillo/include' -I/usr/local/include  -fopenmp -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++17 -I"/opt/R/4.1.2/lib/R/include" -DNDEBUG  -I'/home/runner/work/_temp/Library/Rcpp/include' -I'/home/runner/work/_temp/Library/RcppArmadillo/include' -I/usr/local/include  -fopenmp -fpic  -g -O2  -c arr3d.cpp -o arr3d.o
g++ -std=gnu++17 -I"/opt/R/4.1.2/lib/R/include" -DNDEBUG  -I'/home/runner/work/_temp/Library/Rcpp/include' -I'/home/runner/work/_temp/Library/RcppArmadillo/include' -I/usr/local/include  -fopenmp -fpic  -g -O2  -c test-reflect.cpp -o test-reflect.o
In file included from test-reflect.cpp:2:0:
test-reflect.cpp:36:5:   in constexpr expansion of ‘ExtendedTypeSupport::TypeName<float>()’
Reflect.h:[92](https://github.com/kongdd/hello.R/runs/5064647738?check_suite_focus=true#step:10:92)5:73: error: the value of ‘__PRETTY_FUNCTION__’ is not usable in a constant expression
     static constexpr auto typeStr = ExtendedTypeSupport::TypeName<Type>(); \
                                                                         ^
Reflect.h:43:17: note: in definition of macro ‘ML_E’
 #define ML_E(x) x
                 ^
Reflect.h:51:23: note: in expansion of macro ‘DESCRIBE_FIELD’
 #define ML_3(f,a,...) f(a) ML_E(ML_2(f,__VA_ARGS__))
                       ^
Reflect.h:46:19: note: in expansion of macro ‘ML_3’
 #define ML_C(x,y) x##y
                   ^
Reflect.h:1[95](https://github.com/kongdd/hello.R/runs/5064647738?check_suite_focus=true#step:10:95):25: note: in expansion of macro ‘ML_N’
 #define FOR_EACH(f,...) ML_N(COUNT_ARGUMENTS(__VA_ARGS__),f,__VA_ARGS__)
                         ^~~~
Reflect.h:957:5: note: in expansion of macro ‘FOR_EACH’
     FOR_EACH(DESCRIBE_FIELD, __VA_ARGS__) \
     ^~~~~~~~
test-reflect.cpp:36:5: note: in expansion of macro ‘REFLECT’
     REFLECT(FuelTank, capacity, currentLevel, tickMarks)
     ^
Reflect.h:592:16: note: ‘__PRETTY_FUNCTION__’ was not declared ‘constexpr’
         view = __PRETTY_FUNCTION__;

PRETTY_FUNCTION not being usable in constexpr is a problem in GCC before version 8.1 or so; if possible, update to a later version of GCC (e.g. I have success on GCC 10.2 https://godbolt.org/z/hK184h but fails with your same error if I select GCC 7.5).

If not possible then note that getTypeView is how RareCpp gets types as strings - you may or may not be able to find an alternative method for getting the type strings in earlier versions of GCC; if you can live without constexpr type names you can replace the #if #else's there with just view = "unknown"; and maybe put some similar non-constexpr logic using PRETTY_FUNCTION in TypeToStr for wherever you need to use it.

Thanks for your quick response. I will have a try.

Thank you. Indeed, Reflect.h works well for GCC higher than version 8.1.
When changed ubuntu v18.04 into v20.04, the error disappears.
https://github.com/kongdd/hello.R/actions/runs/1795099938

Thanks for your awesome work!