c++warningsnvcc

CUDA: NVCC gives controlling expression is constant warning on assert


I get the warning controlling expression is constant on assert statement like this:

assert(... && "error message");

Why this warning on this assert? How can I suppress this warning?

NVCC is the NVIDIA cuda compiler, I think it is based on LLVM. Why does it give this warning, when the same compiles fine with GCC or Visual C++ compilers?


Solution

  • A portable alternative (possibly wrapped in a macro) would be something like:

     {
         const bool error_message = true;
         assert([...] && error_message);
     }
    

    To clear up what i meant:

    #define myAssert(msg, exp) { const bool msg(true); assert(msg && (exp)); }
    // usage:
    myAssert(ouch, a && b);
    

    ... gives e.g.:

    assertion "ouch && (a && b)" failed [...]