better-enums
better-enums copied to clipboard
Compiling example code: 5-map.cc fail
Hi,
This is a wonderful library I am looking for. However, when I am trying to compile the example code from the master branch, It fails with an error message:
5-map.cc:44:1: error: body of ‘constexpr’ function ‘constexpr const char* describe(Channel)’ not a return-statement
44 | }
| ^
make: *** [Makefile:20: 5-map.exe] Error 1
The g++ version I am using:
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks!
-Yuxin
Thanks!
Does the example work if you remove this line from describe?
return "needed for gcc 5";
What is the command line you are using to compile the file? In particular, what language standard?
@aantron
I found the reason why the case failed to compile.
link
C++11's constexpr functions support exactly one return statement. The restriction was lifted in C++14.
So it doesn't work if only remove the final return line from describe in C++11.