c++ - g++ internal compiler error segmentation fault with recursive constexpr -
i updated g++ version 6.3.0 (g++ (homebrew gcc 6.3.0) 6.3.0), g++: internal compiler error: segmentation fault: 11 (program cc1plus). previous version (i'm not sure around) 5.2 worked. , on 1 of other computers use g++ (ubuntu 5.2.1-22ubuntu2) 5.2.1 , works.
the code is:
constexpr bool checkforprimenumber(const int p, const int t) {     return p <= t or (p % t , checkforprimenumber(p, t + 2)); }  constexpr bool checkforprimenumber(const int p) {     return p == 2 or (p & 1 , checkforprimenumber(p, 3)); }  int main()  {     static_assert(checkforprimenumber(65521), "bug..."); } i compile code with
g++ test.cpp -std=c++11 -fconstexpr-depth=65535 what can possibly work around this?
edit:
bug report sumitted
the error comes stack overflow internally in g++. allegedly able increase stack (on macos 10.11.6). however, did not resolve issue @ hand. came solution, split check 2 branches, here code:
constexpr bool checkforprimenumber(const int p, const int t, const int hi) {     return p < hi , (p <= t or (p % t , checkforprimenumber(p, t + 2, hi))); }  constexpr bool checkforprimenumber(const int p) {     return p == 2 or (p & 1 , (checkforprimenumber(p, 3, 32768) or checkforprimenumber(p, 3+32768, 65536))); }  int main() {     static_assert(checkforprimenumber(65521), ""); } thanks
edit:
as suggested in comments solution may use c++14:
constexpr bool checkforprimenumber(const int p) {     if (p < 2)         return false;     if (p == 2)         return true;     if (~p & 1)         return false;     (int = 3; < p; += 2)     {         if (p % == 0)             return false;     }     return true; } 
Comments
Post a Comment