complie error occurs when using c++1z
Hi, i've encountered some complie error when i passed c++1z option to a complier.
My main.cpp is simple as below.
#include <iostream>
#include <ctime>
#include <croncpp.h>
using namespace std;
int main(void)
{
std::cout<<"End this program"<<std::endl;
std::string sExpression = "0 0/10 * * * *";
auto sCron = cron::make_cron(sExpression);
std::time_t sNow = std::time(nullptr);
std::time_t sNextTime = cron::cron_next(sCron, sNow);
return 0;
}
But when I tried to compile this like below, some error occured.
$g++ -o main main.cpp -isystem ../externals/croncpp/include --std=c++1z
In file included from main.cpp:4:0:
../externals/croncpp/include/croncpp.h: In function ‘constexpr bool cron::utils::contains(std::string_view, char)’:
../externals/croncpp/include/croncpp.h:333:63: error: call to non-constexpr function ‘std::basic_string_view<_CharT, _Traits>::size_type std::basic_string_view<_CharT, _Traits>::find_first_of(_CharT, std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]’
return CRONCPP_STRING_VIEW_NPOS != text.find_first_of(ch);
~~~~~~~~~~~~~~~~~~^~~~
Without the --std=c++1z option, it complied without any complaints.
My complier version is gcc version 7.2.1 20170829 (Red Hat 7.2.1-1) (GCC)
As of August 2017, the release date of gcc v7.2, the C++17 standard was still in draft form. The gcc v7 manual (https://gcc.gnu.org/gcc-7/changes.html) states that:
The C++ front end has experimental support for all of the current C++17 draft with the -std=c++1z
The non-experimental support of C++17 by gcc occurred with gcc v9 (https://gcc.gnu.org/gcc-9/changes.html).
Under these conditions, this is no surprise that croncpp does not compile with gcc v7. With recent gcc versions, the -std=c++1z flag (now equivalent to -std=c++17) succeed to compile the aformentionned main.cpp.