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

            Bug ID: 105560
           Summary: Spurious -Wunused-local-typedefs warning on a typedef
                    used on returned type
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/zcY11ezev

#include <type_traits>
#include <utility>

template <typename F>
typename F::Out call(F&& fun) {
    typename F::Out var = fun(1);
    return var;
}

void test() {
    // Fill builder with bson-encoded elements from view.
    auto decorateLambda = [](auto&& lambda) {
        using Lambda = std::remove_reference_t<decltype(lambda)>;
        struct DecoratedLambda : Lambda {
            using Out = bool;
        };
        return DecoratedLambda{std::forward<decltype(lambda)>(lambda)};
    };
    call(decorateLambda([&](auto&& value) {
        (void)(value);
        return true;
    }));
}

With -O2 -std=c++20 -Wall:

<source>: In lambda function:
<source>:15:19: warning: typedef 'using
test()::<lambda(auto:1&&)>::DecoratedLambda::Out = bool' locally defined but
not used [-Wunused-local-typedefs]
   15 |             using Out = bool;
      |                   ^~~
Compiler returned: 0


However, DecoratedLambda::Out *is* used by call(), both in the signature and in
the body. Perhaps the issue is that typedefs in local types that are returned
(or are reachable from returned types) shouldn't be considered "local"?

Reply via email to