title: How to avoid an "unreachable statement" due to compile-time-computed values?
body: <p>If I write the following CUDA code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  template &lt;unsigned N&gt;
  __global__ void foo()
  {
      printf("In kernel foo() with N = %u\n", N);
      if (N &lt; 10) { return; }
      printf("Wow, N is really high!\n");
      /* a whole lot of code here which I don't want to indent */
  }
  
  int main() {
      foo&lt;5&gt;&lt;&lt;&lt;1,1&gt;&gt;&gt;();
      foo&lt;20&gt;&lt;&lt;&lt;1,1&gt;&gt;&gt;();
      return 0;
  }
  </code></pre>
  
  <p>I get a compiler warning:</p>
  
  <pre><code>a.cu(8): warning: statement is unreachable
            detected during instantiation of "void foo&lt;N&gt;() [with N=5U]" 
  (12): here
  </code></pre>
  
  <p>I "feel" I shouldn't be getting this warning, since the unreachable code is only unreachable for certain values of the template parameter. And if I write the "CPU equivalent", so to speak:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  
  template &lt;unsigned N&gt;
  void foo()
  {
      std::printf("In kernel foo() with N = %u\n", N);
      if (N &lt; 10) { return; }
      std::printf("Wow, N is really high!\n");
      /* a whole lot of code here which I don't want to indent */
  }
  
  int main() {
      foo&lt;5&gt;();
      foo&lt;20&gt;();
      return 0;
  }
  </code></pre>
  
  <p>and build this with gcc (5.4.0) - I don't get any warnings, even if I compile with <code>-Wall</code>.</p>
  
  <p>Now, I can circumvent this by writing</p>
  
  <pre><code>if (not (N &lt; 10)) { 
      printf("Wow, N is really high!\n");
      /* a whole lot of code here which I don't want to indent */
  }
  </code></pre>
  
  <p>but I would rather avoid having to reverse my logic to jump through nvcc's "hoop". I could also write</p>
  
  <pre><code>if (not (N &lt; 10)) { 
      return;
  }
  else {
      printf("Wow, N is really high!\n");
      /* a whole lot of code here which I don't want to indent */
  }
  </code></pre>
  
  <p>but - I don't want to indent all that code (and the same problem may occur again, requiring even more indentation inside the else block.</p>
  
  <p>Is there something I could do? Also, isn't this a "bug", or a misfeature I should report as a bug?</p>