public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying
@ 2022-03-04 19:07 arthur.j.odwyer at gmail dot com
  2022-03-05  0:32 ` [Bug c++/104792] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2022-03-04 19:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104792
           Summary: [g++ and/or libstdc++] Wunused-local-typedefs + C++20
                    concepts = 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 <iterator>
void test() {
    struct It {
        using value_type = int;
        using difference_type = int;
        int& operator*() const;
        It& operator++();       // X
        It operator++(int);     // X
    };
    static_assert(std::is_same_v<std::iter_value_t<It>, int>);
    static_assert(std::is_same_v<std::iter_rvalue_reference_t<It>, int&&>);
}

Compile with "g++ -std=c++20 -W -Wall" and libstdc++.
GCC will give a warning:

    warning: typedef 'using difference_type = int' locally defined but not used
[-Wunused-local-typedefs]
        6 |         using difference_type = 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<It>` 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, when
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, without
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 <iterator>
void test() {
    struct It {
        using value_type = int;
        int& operator*() const;
    };
    static_assert(std::is_same_v<std::iter_value_t<It>, int>);
    static_assert(std::is_same_v<std::iter_rvalue_reference_t<It>, 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.

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

* [Bug c++/104792] [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying
  2022-03-04 19:07 [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying arthur.j.odwyer at gmail dot com
@ 2022-03-05  0:32 ` pinskia at gcc dot gnu.org
  2022-03-06  1:07 ` arthur.j.odwyer at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-05  0:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I cannot reproduce this. Even the godbolt link does not give a warning.

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

* [Bug c++/104792] [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying
  2022-03-04 19:07 [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying arthur.j.odwyer at gmail dot com
  2022-03-05  0:32 ` [Bug c++/104792] " pinskia at gcc dot gnu.org
@ 2022-03-06  1:07 ` arthur.j.odwyer at gmail dot com
  2022-03-06  1:29 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2022-03-06  1:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
@Andrew Pinski: Sorry, looks like my description ended up not matching the
Godbolt (I said "three lines marked X," but there are only two lines marked X,
for example.)

Here's the Godbolt with one of the two lines commented out. The annoying
warning is present. 

// https://godbolt.org/z/Ms4sePPfe
#include <iterator>
void test() {
    struct It {
        using value_type = int;
        using difference_type = int;
        int& operator*() const;
        It& operator++();       // X
//        It operator++(int);     // X
    };
    static_assert(std::is_same_v<
        std::iter_value_t<It>, int>);
    static_assert(std::is_same_v<
        std::iter_rvalue_reference_t<It>, int&&>);
}

$ g++ -std=c++20 -Wall -Wextra test.cpp
test.cpp: In function 'void test()':
test.cpp:6:15: warning: typedef 'using difference_type = int' locally defined
but not used [-Wunused-local-typedefs]
    6 |         using difference_type = int;
      |               ^~~~~~~~~~~~~~~

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

* [Bug c++/104792] [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying
  2022-03-04 19:07 [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying arthur.j.odwyer at gmail dot com
  2022-03-05  0:32 ` [Bug c++/104792] " pinskia at gcc dot gnu.org
  2022-03-06  1:07 ` arthur.j.odwyer at gmail dot com
@ 2022-03-06  1:29 ` pinskia at gcc dot gnu.org
  2022-03-06  1:39 ` [Bug c++/104792] Wunused-local-typedefs with typedef/type alias defined in struct that is defined in a function scope pinskia at gcc dot gnu.org
  2022-03-07 10:46 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-06  1:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-reduction
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-03-06

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Interesting clang also warns but I think the warning is not needed even if it
is a local defined alias, it is defined inside the struct itself rather than in
the function scope.

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

* [Bug c++/104792] Wunused-local-typedefs with typedef/type alias defined in struct that is defined in a function scope
  2022-03-04 19:07 [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying arthur.j.odwyer at gmail dot com
                   ` (2 preceding siblings ...)
  2022-03-06  1:29 ` pinskia at gcc dot gnu.org
@ 2022-03-06  1:39 ` pinskia at gcc dot gnu.org
  2022-03-07 10:46 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-06  1:39 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-reduction             |
            Summary|[g++ and/or libstdc++]      |Wunused-local-typedefs with
                   |Wunused-local-typedefs +    |typedef/type alias defined
                   |C++20 concepts = annoying   |in struct that is defined
                   |                            |in a function scope

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
void test() {
    struct It {
        using value_type = int;
        using difference_type = int;
    };
    It *t = 0;
}

The warning for the two type alias (typedef) does not make sense here really.
If the struct It was not defined in the function scope, GCC (and clang) does
not warn.

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

* [Bug c++/104792] Wunused-local-typedefs with typedef/type alias defined in struct that is defined in a function scope
  2022-03-04 19:07 [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying arthur.j.odwyer at gmail dot com
                   ` (3 preceding siblings ...)
  2022-03-06  1:39 ` [Bug c++/104792] Wunused-local-typedefs with typedef/type alias defined in struct that is defined in a function scope pinskia at gcc dot gnu.org
@ 2022-03-07 10:46 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-07 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is PR 61596, specifically PR 61596 comment 5.

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

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

end of thread, other threads:[~2022-03-07 10:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04 19:07 [Bug c++/104792] New: [g++ and/or libstdc++] Wunused-local-typedefs + C++20 concepts = annoying arthur.j.odwyer at gmail dot com
2022-03-05  0:32 ` [Bug c++/104792] " pinskia at gcc dot gnu.org
2022-03-06  1:07 ` arthur.j.odwyer at gmail dot com
2022-03-06  1:29 ` pinskia at gcc dot gnu.org
2022-03-06  1:39 ` [Bug c++/104792] Wunused-local-typedefs with typedef/type alias defined in struct that is defined in a function scope pinskia at gcc dot gnu.org
2022-03-07 10:46 ` redi 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).