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

            Bug ID: 107587
           Summary: Explicit specializations of user-defined deduction
                    guides in unnamed namespaces trigger -Wunused-function
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: development at jordi dot vilar.cat
  Target Milestone: ---

After https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53711, functions in unnamed
namespace may trigger -Wunused-function.

Explicit (full) specializations of member functions don't have the `template<>`
prefix. User-defined deduction guides follow the same syntax, and maybe this
confuses the compiler as they trigger -Wunused-function when inside an unnamed
namespace, but (maybe partially specialized) templated user-defined deduction
guides, that is, those with the `template<...>` prefix, don't.

The following valid code compiles cleanly with clang (and even msvc!!!), but
triggers -Wunued-function in gcc-12 (and older) just compiling wit -Wall:

```
template<typename T> struct X { X(T) {} };
X(bool) -> X<int>;

namespace
{
    template<typename T> struct Y { Y(T) {} };
    Y(bool) -> Y<int>;
}

void test()
{
    [[maybe_unused]] X<int> x = X{false};
    [[maybe_unused]] Y<int> y = Y{false};
}
```


It is demoed in Compiler Explorer: https://godbolt.org/z/rf3zrEzsd.

Reply via email to