Bug 71863 - wrong column location in -Wformat in C++
Summary: wrong column location in -Wformat in C++
Status: RESOLVED DUPLICATE of bug 56856
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2016-07-13 18:47 UTC by Martin Sebor
Modified: 2016-07-13 18:47 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2016-07-13 18:47:13 UTC
When compiled in C mode, the following test emits warnings that point at each of the problem directives:

$ cat xyz.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wformat xyz.c
void f (void)
{
  __builtin_printf ("%s%s", 0, 0);
}
xyz.c: In function ‘f’:
xyz.c:3:23: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
   __builtin_printf ("%s%s", 0, 0);
                       ^
xyz.c:3:25: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
   __builtin_printf ("%s%s", 0, 0);
                         ^

However, when compiled in C++ mode, the column information is wrong:

$ cat xyz.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wformat -xc++ xyz.c
void f (void)
{
  __builtin_printf ("%s%s", 0, 0);
}
xyz.c: In function ‘void f()’:
xyz.c:3:33: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat=]
   __builtin_printf ("%s%s", 0, 0);
                                 ^
xyz.c:3:33: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘int’ [-Wformat=]

The same problem occurs with other directives.  I found a long discussion of some of the issues in bug 52952 but based on the patches referenced from there it looks like they have been resolved (as least for C).
Comment 1 Martin Sebor 2016-07-13 18:47:59 UTC
Bug 56856 already tracks this problem.

*** This bug has been marked as a duplicate of bug 56856 ***