1

Given tmp.cpp:

#include <stdio.h>

#pragma report(disable, CCN8826)

int main(int argc, const char *argv[])
{
    const char * hi = "hi\n";
    printf(hi);

    return 0;
}

Despite I use #pragma report that is supposed to suppress the warning, I still get:

bash-3.1$ xlC -qformat=all tmp.cpp
"tmp.cpp", line 8.12: 1540-2826 (W) The format string is not a string literal 
and format arguments are not given.

How do I get rid of that warning?

The error message numbers are here and the #pragma report description is here. My compiler is IBM XL C/C++ Advanced Edition for Blue Gene/P, V9.0

Anton Daneyko
  • 6,528
  • 5
  • 31
  • 59
  • 2
    The message identifier in your `#pragma` statement and the compiler warning do not match. Maybe you should be using `#pragma report(disable, CCN2826)` instead? – Praetorian Dec 13 '12 at 16:14
  • Well you explicitly told it to turn on all format diagnostic messages... – user7116 Dec 13 '12 at 16:16
  • 1
    @Praetorian: actually CCN8826 is the compiler message identifier per the user manual. – user7116 Dec 13 '12 at 16:18
  • @sixlettervariables You wrote `CNN8826` and the question contains `CCN8826`, another discrepancy :). Anyway, I was just taking a potshot; I've never used this compiler. – Praetorian Dec 13 '12 at 16:20
  • @Praetorian as sixlettervariables mentioned the compiler message identifier is taken from the only manual which I have found to mention this error (http://ibm.co/SYEOrr). It is however the manual for the other IBM compiler. I could not find any references to "The format string is not a string literal ..." in the original reference here: http://ibm.co/12pfMof – Anton Daneyko Dec 14 '12 at 12:21

4 Answers4

2

I know it doesn't directly answer your question but you could presumably avoid the warning by changing your code to

printf("%s", hi);

In case you have:

void f(char * s) { printf(s); }

you can modify it as:

void f(char * s) { printf("%s", s); }

to get rid of the warning.

EDIT: An easy, slightly limited, probably nasty way of dealing with your new issue would be

char buf[1024];
snprintf(buf, sizeof(buf), "%s %s", "bloody", "warning");
fprintf(stderr, "%s", buf);

It may be possible to generalise this to something like the following (untested!)

my_printf(const char* fmt, ...)
{
    va_list ap;
    char buf[1024];
    vsnprintf(buf, sizeof(buf), fmt, ap);
    fprintf(stderr, "%s", buf);
}
simonc
  • 41,632
  • 12
  • 85
  • 103
  • In this particular case it would help, but this is only an example to make it clear what I wanted to do. The original code looks conceptually like that: `void function(char * s) { fprintf(stderr, s); }` – Anton Daneyko Dec 14 '12 at 12:09
  • @mezhaka The same type of workaround could apply - `void function(char * s) { fprintf(stderr, "%s", s); }` – simonc Dec 14 '12 at 12:13
  • That is so smart! I envy you came up with this! I am going to edit and accept you answer. – Anton Daneyko Dec 14 '12 at 13:32
  • Heck, I've bumped into this again, I still cannot do a this: `char* format = "%s %s"; printf(format, "bloody", "warning");`. I cannot use the `printf("%s", s)` trick here... – Anton Daneyko Jan 23 '13 at 20:35
  • I've updated my answer with a workaround for this new format and a speculative approach for a more general solution. Just in case you've made recent progress with it, disabling the warning would be neater than either of my suggestions :-) – simonc Jan 23 '13 at 22:09
  • Thanks for the update. Nope, still do not know how to disable it, but in a couple of weeks I am going to meet some guys from IBM, who might shred light on this annoyance. – Anton Daneyko Jan 24 '13 at 08:54
2

As the message indicates, its message identifier is 1540-2826, therefore change the #pragma report to:

#pragma report(disable, "1540-2826")

Dwayne Moore
  • 376
  • 1
  • 2
0

You can tell the compiler not to generate this warning (for any code, not just the line in question) by passing the flag -qsuppress=1540-2826.

To suppress multiple warnings, separate the codes with a semicolon e.g. -qsuppress=1540-2826:1540-0809.

Josh Milthorpe
  • 956
  • 1
  • 14
  • 27
0

The error message IDs produced by IBM XL C++ depend on the operating system. On z/OS the message IDs look like CCN8826, but elsewhere they look like 1540-2826.

On z/OS UNIX System Services, compiling your code using xlc++ tmp.cpp yields no warnings or errors. In any case, adding

-qsuppress=CCN8826

to the xlc++ command line ought to do the trick there if that error does show up. Based on Josh Milthorpe's answer,

-qsuppress=1540-2826

should work on operating systems where that message ID format is used.

Note that not all messages can be suppressed, so if you get a complaint about the message you're trying to suppress then that may be because that particular message cannot be suppressed, even if you are using the correct format for specifying a message to suppress.

The z/OS V2R2 XL C/C++ Messages document suggests that only message numbers 3000 through 4399 (for C), and 5001 through 6999 and 7500 through 8999 (for C++) can be suppressed. If I specify -qsuppress=CCN1142 on z/OS UNIX System Services for a source file that yields message CCN1142 then I get a complaint about 'Unrecognized value "CCN1142" specified with option "SUPPRESS".' and message CCN1142 continues to be reported. -qsuppress=CCN8826 produces no complaint.

Louis Strous
  • 942
  • 9
  • 15