views:

314

answers:

3

I have the following warning:

"controlling expression is constant"

because of assert statement like this:

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

how can I suppress warning from this particular line? The compiler I use is NVIDIA cuda compiler. I think it is llvm based.

okay, it may not be llvm, as the pragma's do not have any affect. The Boolean replacement is not something I want. The idea is to print longer helpful error message when assert fails. The code works but the warning messages junk the output.

#pragma warning disable

does not have an effect either. Probably should mention that I am on Linux if it matters

okay it is GCC, however the usual GCC ignored pragma has no affect. I understood the Boolean part but I would like to print some special characters, such as *. However the Boolean thing might be okay

definitely GCC, at least as far as the macros are concerned. Thanks

A: 

If it is LLVM based, then you can use something like this:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmultichar"

char b = 'df'; // no warning.

#pragma clang diagnostic pop

From Controlling Diagnostics via Pragmas.

Frank Krueger
+1  A: 

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 [...]

Georg Fritzsche
A: 

Try #pragma warning.

Crashworks