public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc -Wconversion
@ 2019-08-06 15:55 David Aldrich
  2019-08-06 18:10 ` Richard Sandiford
  0 siblings, 1 reply; 3+ messages in thread
From: David Aldrich @ 2019-08-06 15:55 UTC (permalink / raw)
  To: gcc-help

Hi

For our large 64-bit C++ project we use gcc compile options: -Wall -pedantic

We also build the project with Visual C++ and get lots of instances of
warning C4267, for example:

'initializing': conversion from 'size_t' to 'unsigned int', possible loss
of data

To get a similar warning with gcc it seems that I need -Wconversion.
However, that warning option seems very strict. For example with this code:

typedef struct
{
    uint8 x : 4,
             y  : 4;
} myHdr;

unsigned X=1;
myHdr hdr;

hdr.x = static_cast<uint8_t>(X);

I get warning:

warning: conversion to ‘unsigned char:4’ from ‘uint8_t {aka unsigned char}’
may alter its value [-Wconversion]

I have two questions:

1) What static_cast would I use to fix the above example warning?

2) Is -Wconversion recommended or is it too fussy in practice? Is there a
better option?

Best regards

David

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

end of thread, other threads:[~2019-08-07 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06 15:55 gcc -Wconversion David Aldrich
2019-08-06 18:10 ` Richard Sandiford
2019-08-07 15:40   ` David Aldrich

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).