https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70340

            Bug ID: 70340
           Summary: Invalid constexpr template function causes internal
                    compiler error (memory exhaustion)
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gccBugs at haatschii dot de
  Target Milestone: ---

Working with GMP I came across an error which causes the GCC to use an
exhaustive amount of memory (> 32 GB). The problem boils down to the following
example:

#include <gmpxx.h>

template<class T> 
constexpr T pow(const T& _base, const uint64_t _exp) {
        return _exp==0 ? 1 :(_exp%2==0?pow(_base*_base, _exp/2) :
_base*pow(_base, _exp-1));
}


int main ( const int argC, char* argV[] ) {
        mpz_class test = pow( mpz_class(10), 73ul); 
        return 0;
}


Note that this code is invalid because different types are used on the
different sides of the ":" in both ternary operators. This is correctly pointed
out by the g++ if the "constexpr" is removed. However with the "constexpr" it
crashes.

My version is:
g++ (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2)

Best regards,
Sebastian

Reply via email to