I'm writing a templated function* similar to the following:
template <typename T, bool v>
void foo(T t1) {
/* common code */
if (v) {
int i = bar();
/* ... */
return;
}
else {
/* ... */
}
/* more common code */
}
When I compile this and foo
is instantiated with v
set to false, the compiler says:
warning: dynamic initialization in unreachable code
Now, the code is unreachable because of the template argument; and this should be perfectly acceptable. How can I avoid or suppress this warning? I would rather not suppress such warnings altogether.
Notes:
- I would rather not specialize differently for true and false, since there's some common code, and I don't want to duplicate, nor artificially create another function.
- Actually it's a CUDA kernel being compile by NVCC. If you can answer the question more generally, please do, otherwise answer specifically for this case.