title: How to get rid of an enumeral mismatch error in C++?
body: <p>In the book that I found there's a code computing a square root of a given number, but the code doesn't compile. There is a lot of errors when instantiating the template. This is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template
  &lt;int N, int LO=1, int HI=N&gt; class Sqrt {
  public:
      enum { mid = (LO+HI+1)/2 };
  
      enum { result = (N&lt;mid*mid) ? Sqrt&lt;N,LO,mid-1&gt;::result : Sqrt&lt;N,mid,HI&gt;::result };
  };
  
  template&lt;int N, int M&gt; class Sqrt&lt;N,M,M&gt; {
  public:
      enum { result=M };
  };
  
  int main()
  {
      std::cout &lt;&lt; Sqrt&lt;5&gt;::result &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>and many of the warnings are </p>
  
  <pre><code>enumeral mismatch in conditional expression 'Sqrt&lt;5,1,1&gt;::&lt; anonymous enum&gt; vs 'Sqrt&lt;5,2,2&gt;::&lt; anonymous enum&gt;' [-Wenum-compare]    
  </code></pre>
  
  <p>as I tested later this warning is not critical, for example in the code     </p>
  
  <pre><code>class a {
  public:
      enum {test = 0};
  };
  
  class b {
  public:
      enum {test = 1};
  };
  
  class c {
  public:
      enum {test = 2 &lt; 3 ? a::test : b::test};
  };
  
  int main()
  {
      int v = c::test;
  }
  </code></pre>
  
  <p>I get the same warning, but the code compiles. My confusion is caused because if I place the '-Wenum-compare' in compiler options, the first code compiles. What is the real problem here?</p>