public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers
@ 2020-06-19 12:11 redboltz at gmail dot com
  2020-06-19 19:09 ` [Bug libstdc++/95765] " cvs-commit at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: redboltz at gmail dot com @ 2020-06-19 12:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95765
           Summary: std::vector should be built without warnings with
                    -Wconversion and/or -Wsystem-headers
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redboltz at gmail dot com
  Target Milestone: ---

This is similar issue to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50871 but
different one.

Tested on x86-64 g++ 10.1

The following code converts from std::uint32_t to std::uint16_t. It is
dangerous. Even if compile with -Wconversion option, no warnings are reported
because conversion code is in the standard library.

#include <vector>
#include <cstdint>

struct info {
    explicit info(std::uint16_t v): v { v } {}
    std::uint16_t v;
};

int main() {
    std::uint32_t a = 0x10000;
    std::vector<info> i;

    // convert from std::uint32_t to std::uint16_t internally
    // Warning is reported only if -Wsystem-headers
    i.emplace_back(a); 
}

Compile result: https://godbolt.org/z/_LJPAT


In order to report warning, -Wsystem-headers option is required.

Compile result: https://godbolt.org/z/jmkc5W

/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/ext/new_allocator.h:150:4:
warning: conversion from 'unsigned int' to 'uint16_t' {aka 'short unsigned
int'} may change value [-Wconversion]

  150 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

      |    ^

is the expected warning.

However, many other warnings are reported.
It is difficult to find the expected warning.


By the way, user can use the following workaround to report the expected
warning without -Wsystem-headers.

struct info {
    // Possible workaround without -Wconversion
    // Move conversion point to user code
    template <typename T>
    explicit info(T v): v { v } {}
    std::uint16_t v;
};

Compile result: https://godbolt.org/z/f4YKgh

But I think that the std::vector implementation should be compiled without
warnings on -Wconversion and -Wsystem-headers.

I'm not sure the policy which warning checking should be satisfied the standard
library.

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

* [Bug libstdc++/95765] std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers
  2020-06-19 12:11 [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers redboltz at gmail dot com
@ 2020-06-19 19:09 ` cvs-commit at gcc dot gnu.org
  2020-06-19 19:10 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-19 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:5b6215083bd6a3e10dd142e1c5d4fab011d6f074

commit r11-1562-g5b6215083bd6a3e10dd142e1c5d4fab011d6f074
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jun 19 18:15:15 2020 +0100

    libstdc++: Fix some -Wsystem-headers warnings (PR 95765)

            PR libstdc++/95765
            * include/bits/stl_algobase.h (__size_to_integer(float))
            (__size_to_integer(double), __size_to_integer(long double))
            (__size_to_integer(__float128)): Cast return type explicitly.
            * include/bits/stl_uninitialized.h
(__uninitialized_default_1<true>):
            Remove unused typedef.

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

* [Bug libstdc++/95765] std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers
  2020-06-19 12:11 [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers redboltz at gmail dot com
  2020-06-19 19:09 ` [Bug libstdc++/95765] " cvs-commit at gcc dot gnu.org
@ 2020-06-19 19:10 ` redi at gcc dot gnu.org
  2020-06-19 19:12 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-19 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Users should not be routinely using -Wsystem-headers to find problems with
their own code (that defeats the entire purpose of suppressing warnings in
system headers).

I've fixed some warnings in libstdc++ code, but the real problem here is Bug
43167 (and Bug 43167 comment 17 has almost exactly the same example).

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

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

* [Bug libstdc++/95765] std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers
  2020-06-19 12:11 [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers redboltz at gmail dot com
  2020-06-19 19:09 ` [Bug libstdc++/95765] " cvs-commit at gcc dot gnu.org
  2020-06-19 19:10 ` redi at gcc dot gnu.org
@ 2020-06-19 19:12 ` redi at gcc dot gnu.org
  2020-06-19 23:23 ` redboltz at gmail dot com
  2021-03-29 20:05 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-19 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Actually Bug 87614 is the source of that other example, and a more suitable one
to mark this as a duplicate of.

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

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

* [Bug libstdc++/95765] std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers
  2020-06-19 12:11 [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers redboltz at gmail dot com
                   ` (2 preceding siblings ...)
  2020-06-19 19:12 ` redi at gcc dot gnu.org
@ 2020-06-19 23:23 ` redboltz at gmail dot com
  2021-03-29 20:05 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redboltz at gmail dot com @ 2020-06-19 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Takatoshi Kondo <redboltz at gmail dot com> ---
Thank you for fixing the warnings.

> Users should not be routinely using -Wsystem-headers to find problems with their own code (that defeats the entire purpose of suppressing warnings in system headers).
>
> I've fixed some warnings in libstdc++ code, but the real problem here is Bug 43167 (and Bug 43167 comment 17 has almost exactly the same example).

I agree. If warnings relate to templates would be reported without
`-Wsystem-headers`, it is ideal.

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

* [Bug libstdc++/95765] std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers
  2020-06-19 12:11 [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers redboltz at gmail dot com
                   ` (3 preceding siblings ...)
  2020-06-19 23:23 ` redboltz at gmail dot com
@ 2021-03-29 20:05 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-29 20:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:e5431137ca9787f6d8747c1d1c3f85f7b10fde35

commit r10-9612-ge5431137ca9787f6d8747c1d1c3f85f7b10fde35
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jun 19 18:15:15 2020 +0100

    libstdc++: Fix some -Wsystem-headers warnings (PR 95765)

            PR libstdc++/95765
            * include/bits/stl_algobase.h (__size_to_integer(float))
            (__size_to_integer(double), __size_to_integer(long double))
            (__size_to_integer(__float128)): Cast return type explicitly.

    (cherry picked from commit 5b6215083bd6a3e10dd142e1c5d4fab011d6f074)

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

end of thread, other threads:[~2021-03-29 20:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-19 12:11 [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers redboltz at gmail dot com
2020-06-19 19:09 ` [Bug libstdc++/95765] " cvs-commit at gcc dot gnu.org
2020-06-19 19:10 ` redi at gcc dot gnu.org
2020-06-19 19:12 ` redi at gcc dot gnu.org
2020-06-19 23:23 ` redboltz at gmail dot com
2021-03-29 20:05 ` cvs-commit at gcc dot gnu.org

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