public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103862] New: Regression: -Wold-style-cast warns about system macros
@ 2021-12-29 23:38 carlosgalvezp at gmail dot com
  2021-12-29 23:40 ` [Bug c++/103862] " carlosgalvezp at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: carlosgalvezp at gmail dot com @ 2021-12-29 23:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103862

            Bug ID: 103862
           Summary: Regression: -Wold-style-cast warns about system macros
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carlosgalvezp at gmail dot com
  Target Milestone: ---

Hi,

I thought this problem was solved by reading this: 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12258

But I can still find it on GCC 11.1:

// include/third_party.h
#pragma once

#define MY_CAST(x) ((int)x)

// main.cpp
#include <third_party.h>

int main() 
{
    int x = MY_CAST(123);
    return x;
}

# g++-11 -isystem include -Wold-style-cast main.cpp
In file included from main.cpp:1:
main.cpp: In function 'int main()':
main.cpp:5:21: warning: use of old-style cast to 'int' [-Wold-style-cast]
    5 |     int x = MY_CAST(123);
      |                     ^~~

# g++-11 --version
g++-11 (Ubuntu 11.1.0-1ubuntu1~20.04) 11.1.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103862] Regression: -Wold-style-cast warns about system macros
  2021-12-29 23:38 [Bug c++/103862] New: Regression: -Wold-style-cast warns about system macros carlosgalvezp at gmail dot com
@ 2021-12-29 23:40 ` carlosgalvezp at gmail dot com
  2021-12-29 23:47 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: carlosgalvezp at gmail dot com @ 2021-12-29 23:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103862

--- Comment #1 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
The problem exists also in GCC 9.4.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103862] Regression: -Wold-style-cast warns about system macros
  2021-12-29 23:38 [Bug c++/103862] New: Regression: -Wold-style-cast warns about system macros carlosgalvezp at gmail dot com
  2021-12-29 23:40 ` [Bug c++/103862] " carlosgalvezp at gmail dot com
@ 2021-12-29 23:47 ` pinskia at gcc dot gnu.org
  2021-12-29 23:51 ` carlosgalvezp at gmail dot com
  2021-12-30 23:44 ` [Bug c++/103862] " colomar.6.4.3 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-29 23:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103862

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Carlos Galvez from comment #0)
> Hi,
> 
> I thought this problem was solved by reading this: 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12258

That is a different issue, there the expression is fully from the system header
while here the constant is from a non-system header.

It looks like the warning is being based on where the inner expression is from
rather than where the cast is located.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103862] Regression: -Wold-style-cast warns about system macros
  2021-12-29 23:38 [Bug c++/103862] New: Regression: -Wold-style-cast warns about system macros carlosgalvezp at gmail dot com
  2021-12-29 23:40 ` [Bug c++/103862] " carlosgalvezp at gmail dot com
  2021-12-29 23:47 ` pinskia at gcc dot gnu.org
@ 2021-12-29 23:51 ` carlosgalvezp at gmail dot com
  2021-12-30 23:44 ` [Bug c++/103862] " colomar.6.4.3 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: carlosgalvezp at gmail dot com @ 2021-12-29 23:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103862

--- Comment #3 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
Interesting, thanks for the quick reply! In case it helps, if I include the
header as a regular header, I do get the "note" referring to the system header:

# g++-11 -I include -Wold-style-cast main.cpp
In file included from main.cpp:1:
main.cpp: In function 'int main()':
main.cpp:5:21: warning: use of old-style cast to 'int' [-Wold-style-cast]
    5 |     int x = MY_CAST(123);
      |                     ^~~
include/third_party.h:3:26: note: in definition of macro 'MY_CAST'
    3 | #define MY_CAST(x) ((int)x)
      |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103862] -Wold-style-cast warns about system macros
  2021-12-29 23:38 [Bug c++/103862] New: Regression: -Wold-style-cast warns about system macros carlosgalvezp at gmail dot com
                   ` (2 preceding siblings ...)
  2021-12-29 23:51 ` carlosgalvezp at gmail dot com
@ 2021-12-30 23:44 ` colomar.6.4.3 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2021-12-30 23:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103862

Alejandro Colomar <colomar.6.4.3 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |colomar.6.4.3 at gmail dot com

--- Comment #4 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Hi,

I tried GCC 12 from Debian experimental and I can still reproduce the bug:

$ g++-12 --version
g++-12 (Debian 12-20211217-1) 12.0.0 20211217 (experimental) [master
r12-6027-g774269aa4b9]


I found something weird: if you enclose the macro argument in parentheses, the
warning is silenced:

    #define MY_CAST(x) ((int)(x))


P.S.: If system header macros can be warned if part of the expression comes
from user code, I'd really like see -Wsizeof-pointer-div reporting warnings. 
See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94746>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-30 23:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-29 23:38 [Bug c++/103862] New: Regression: -Wold-style-cast warns about system macros carlosgalvezp at gmail dot com
2021-12-29 23:40 ` [Bug c++/103862] " carlosgalvezp at gmail dot com
2021-12-29 23:47 ` pinskia at gcc dot gnu.org
2021-12-29 23:51 ` carlosgalvezp at gmail dot com
2021-12-30 23:44 ` [Bug c++/103862] " colomar.6.4.3 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).