From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD9C63858D39; Fri, 4 Mar 2022 19:07:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD9C63858D39 From: "arthur.j.odwyer at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying Date: Fri, 04 Mar 2022 19:07:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: arthur.j.odwyer 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, 04 Mar 2022 19:07:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104792 Bug ID: 104792 Summary: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts =3D annoying Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arthur.j.odwyer at gmail dot com Target Milestone: --- This might be considered "not a bug", or "duplicate of #61596", or "bug but= in a different way from what Arthur suggests," so I'm going to give the non-reduced test case and let one of you (@jwakely perhaps) worry about how= to reduce it. // https://godbolt.org/z/v9Wv8vY3G #include void test() { struct It { using value_type =3D int; using difference_type =3D int; int& operator*() const; It& operator++(); // X It operator++(int); // X }; static_assert(std::is_same_v, int>); static_assert(std::is_same_v, int&&>); } Compile with "g++ -std=3Dc++20 -W -Wall" and libstdc++. GCC will give a warning: warning: typedef 'using difference_type =3D int' locally defined but no= t used [-Wunused-local-typedefs] 6 | using difference_type =3D int; | ^~~~~~~~~~~~~~~ However, if you then delete any of the three lines marked "X", the warning = will go away again. I believe this is because `iter_value_t` relies on a C++20 Concepts constraint where `difference_type` *is* checked when `It` is an `input_iterator`, but is *not* checked when `It` is not an iterator. So, wh= en these precise three operators exist, the typedef isn't unused, but when any= one of them doesn't exist, GCC gives the unused-typedef warning. I claim that the user-programmer shouldn't be responsible for tracking the internal implementation details of the constraints of `std::iter_value_t`. I just want to make a local type that has all the pieces of an iterator, with= out GCC helpfully getting in the way and warning me that *right now* (according= to the internal implementation details of libstdc++) some of those pieces aren= 't being used. I admit that in this case the warning is surfaced only when I *fail* to implement one of those three member functions, so I actually have *not* implemented "all the pieces of an iterator" in this test case. I'm betting = that it's possible to reproduce this annoying issue, somewhere in libstdc++, even without that caveat, though. For now, I'll silence the warning by removing my unused typedef `difference_type`, i.e. #include void test() { struct It { using value_type =3D int; int& operator*() const; }; static_assert(std::is_same_v, int>); static_assert(std::is_same_v, int&&>); } But I'm uncomfortable with that, because I don't know if later revisions/bugfixes to the library will require me to re-add those pieces I'= ve removed.=