[Bug c++/87292] New: Warnings with Bit Fields

2018-09-12 Thread nunojpg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87292

Bug ID: 87292
   Summary: Warnings with Bit Fields
   Product: gcc
   Version: 8.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: nunojpg at gmail dot com
  Target Milestone: ---

#include 
#include 

int main()
{
struct{
uint8_t c1:6;
uint8_t c2:6;
} a;
auto c = {a.c1, a.c2}; //warning: narrowing conversion of '(unsigned
char)c1' from 'unsigned char' to 'unsigned char:6' [-Wnarrowing]

enum class Bool{False=0, True=1};
struct{
Bool v:1; //warning: 'v' is too small to hold all values of 'enum class
main()::Bool'
} b;

return 0;
}

I get this 2 warnings with g++, including trunk, but not with clang++.

I believe the first case is a bug, c1 is promoted to uint8_t and then is
truncated back to uint8_t:6.

The second case I am not sure if the warning is reasonable. For example clang++
will also not warn if the enum class have values defined that do not fit, and
instead will only warn if it detects a assignment that causes truncation.

[Bug c++/87292] Warnings with Bit Fields

2018-09-12 Thread nunojpg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87292

--- Comment #2 from Nuno Gonçalves  ---
Not the case since, same warning if:

enum class Bool : uint8_t {False=0, True=1}

[Bug c++/87292] Warnings with Bit Fields

2018-09-12 Thread nunojpg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87292

--- Comment #3 from Nuno Gonçalves  ---
Also to add, this could be suppressed if 

enum class Bool : bool{False=0, True=1};

So a better example is for a 2 bit BitField:

enum class Nr : uint8_t{Zero=0, One=1, Two=2, Three=3};
struct{
 Nr v:2;
} b;

[Bug c++/87292] Warnings with Bit Fields

2018-09-13 Thread nunojpg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87292

--- Comment #4 from Nuno Gonçalves  ---
I found that the issue with enum have been extensively debated at #61414.
Sorry.

So actually this bug report is only regarding the warning with initializer
list:

struct{
uint8_t c1:6;
uint8_t c2:6;
} a;
auto c = {a.c1, a.c2}; //warning: narrowing conversion of '(unsigned
char)c1' from 'unsigned char' to 'unsigned char:6' [-Wnarrowing]

[Bug lto/116515] New: LTO link time prints warning for system headers

2024-08-28 Thread nunojpg at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116515

Bug ID: 116515
   Summary: LTO link time prints warning for system headers
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: lto
  Assignee: unassigned at gcc dot gnu.org
  Reporter: nunojpg at gmail dot com
  Target Milestone: ---

With the following program:

```
#define FMT_HEADER_ONLY

#include 

#include 

int main(int, char **argv)
{
std::filesystem::path p{argv[0]};
fmt::print("{}", p);
return 0;
}
```

root@f351f435510a:/# g++ -Wextra -O3 -DNDEBUG -flto=auto main.cpp -isystem
fmt/include
In function 'copy',
inlined from 'for_each_codepoint' at fmt/include/fmt/format.h:682:13,
inlined from 'find_escape' at fmt/include/fmt/format.h:1852:21,
inlined from 'write_escaped_string' at fmt/include/fmt/format.h:1944:30,
inlined from 'write_escaped_path' at fmt/include/fmt/std.h:105:60,
inlined from 'format' at fmt/include/fmt/std.h:157:31:
fmt/include/fmt/base.h:1220:31: warning: writing 8 bytes into a region of size
7 [-Wstringop-overflow=]
 1220 |   while (begin != end) *out++ = static_cast(*begin++);
  |
...

Multiple -Wstringop-overflow warnings are printed for fmt, despite fmt being
included as a system header.

This happens at link time and not compile time, and only when using LTO.

LTO doesn't appear to be respecting system headers tag for hidding warnings.


Tested with:
gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
g++ (Debian 14.2.0-1) 14.2.0