Could you please explain why this code doesn't compile?
// source.cpp
constexpr const char* func(const char* s) { return s;}
constexpr bool find(const char *param) {
constexpr const char* result = func(param);
return (param == 0);
}
int main()
{
constexpr bool result = find("abcde");
}
The compile command:
$ g++ -std=c++14 source.cpp
I've tried gcc5.4 and gcc6.4. The error:
source.cpp: In function ‘constexpr bool find(const char*)’:
source.cpp:5:46: error: ‘param’ is not a constant expression
constexpr const char* result = func(param);
^
constexprdefinition of find. See en.cppreference.com/w/cpp/language/constexpr