https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80299
Bug ID: 80299 Summary: No ordinary unqualified lookup for operators from default template arguments Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kaballo86 at hotmail dot com Target Milestone: --- The following snippet results in a compilation error: struct X {}; namespace ns { bool operator==(X const&, X const&); template <typename T, typename R = decltype(T{} == T{})> void check() {} // note: substitution failed, no 'operator==' } int main() { ns::check<X>(); // error: no match } Unqualified lookup is not being done for `operator==`. This other snippet further shows that the kind of lookups being done depends on the context; within a default template argument only argument dependent lookup is being done, while within the function template body unqualified lookup finds a better match. struct B {}; struct X : B {}; void operator==(B const&, B const&); namespace ns { bool operator==(X const&, X const&); template <typename T, typename R = decltype(T{} == T{})> void check(T v) { decltype(T{} == T{}) rb = (v == v); // ok, bool R rv = (v == v); // error, void } } int main() { X x; ns::check(x); } Neither snippet fails if using function call syntax, `operator==(T{}, T{})`, instead.