Equivalent of `#pragma GCC diagnostic ignored "-Wunused-variable"` in nvc++

I have a place, where I generate a variable on host which is unused, due to which I get a warning from nvc++ to the effect of variable "xyz" was declared but never referenced. I wonder if there is a pragma directive to supress that specific warning.

First use the “–display_error_number” to get the warning’s number, the use “–diag_suppress” to suppress it.

% nvc++ test.cpp --display_error_number
"test.cpp", line 5: warning #177-D: variable "j" was declared but never referenced
     int i,j;
           ^

% nvc++ test.cpp --diag_suppress177
% 

See: HPC Compiler Reference Manual Version 22.7 for ARM, OpenPower, x86

Hope this helps,
Mat

Thank you for your reply. Is there something that only works locally with the specific line of code which I want to suppress rather than the complete TU?

I couldn’t find this in our documentation, so had to look at EDG’s docs (we use EDG’s front end C++), and found the “diag_supress” and “diag_warning” pragmas can be used to toggle a warning on or off.

For example here the unused warning is only emitted for the second use but not the first.

#include <stdio.h>
#include <stdlib.h>

#pragma diag_suppress 177
void foo () {
   int i,j;
   i = 1;
   printf("foo i=%d\n",i);
   return;
}
#pragma diag_warning 177
void bar() {
   int k,l;
   k = 1;
   printf("bar k=%d\n",k);
   return;
}
% nvc++ -c test.cpp
"test.cpp", line 13: warning: variable "l" was declared but never referenced
     int k,l;
           ^

This is wonderful. Thanks a lot for your help.