From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7959C388A827; Fri, 19 Jun 2020 12:11:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7959C388A827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592568702; bh=2iEv70bMz24UNc1BQIPcUbwdkZG4PlWt8C8zgHYYZWw=; h=From:To:Subject:Date:From; b=qtbe+omduGhwqMN84/38fG2kFl1Bbr3OaiNSpPyYyYDHPokvpPGeVsiRshilwVc5/ KIL3UKpvNpEwkL9iABispVn5W6vAU28sFuEd8RmKyuVmlY5OG2o+NWq2RdoVBMeJv0 qeZu5RKjJbGRoa7FA6oFuwBCWRpLyy2SMdI+Ozdo= From: "redboltz at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/95765] New: std::vector should be built without warnings with -Wconversion and/or -Wsystem-headers Date: Fri, 19 Jun 2020 12:11:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redboltz at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jun 2020 12:11:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95765 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=3D508= 71 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 report= ed because conversion code is in the standard library. #include #include struct info { explicit info(std::uint16_t v): v { v } {} std::uint16_t v; }; int main() { std::uint32_t a =3D 0x10000; std::vector i; // convert from std::uint32_t to std::uint16_t internally // Warning is reported only if -Wsystem-headers i.emplace_back(a);=20 } 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:15= 0: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 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 stan= dard library.=