How can I avoid the warning "dynamic initialization in unreachable code"?

I am writing a template 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 foocreate using vset to false, the compiler says:

warning: dynamic initialization in unreachable code

Now the code is unreachable due to the template argument; and that should be perfectly acceptable. How can I avoid or suppress this warning? I would rather not suppress such warnings at all.

Notes:

  • I would prefer not to specialize differently for true and false, since there is a common code there, and I do not want to duplicate, as well as artificially create another function.
  • ​​CUDA NVCC. , , , .
+4
1

, ( , NVCC). v=true if(v) -statement .

, , .

GCC , , :

#pragma GCC diagnostic ignored "-Wunreachable-code"

edit: , , , , . : http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

: nvcc

+4

Source: https://habr.com/ru/post/1533694/


All Articles