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

            Bug ID: 81134
           Summary: C++ partial template specialization issue
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manish.baphna at citi dot com
  Target Milestone: ---

Following code going into recursive template instantiation without realizing
terminating case. Works find with clang.

template <int N, int  M>                                      
struct GCD
{  
   static const int value = (N>M)? GCD<N%M, M>::value : GCD<N, M%N>::value;  
};                                                                             
                                                                              
template <int M>                                                             
struct GCD<0, M>{                                                              
                   static const int value = M;                                  
};                                                                              
template <int M> 
struct GCD<M, 0>
{
 static const int value = M ;     
};                                                                              
int main()                                                                      
{    
    static_assert(GCD<12,15>::value == 3, "Error");
} 

Error: g++ lcd.cpp -std=c++11
fatal error: template instantiation depth exceeds maximum of 900 (use
-ftemplate-depth= to increase the maximum)
  static const int value = (N>M)? GCD<N%M, M>::value : GCD<N, M%N>::value;

Reply via email to