Skip to content

Warn when a template class declares a dependent friend function [-Wnon-template-friend] #23716

Open
@rnk

Description

@rnk
Bugzilla Link 23342
Version unspecified
OS All

Extended Description

The out-of-line friend declaration is very likely broken because the declaration is not part of the template. GCC has a -Wnon-template-friend warning that finds this.

template <typename T>
struct Arg {
  friend bool operator==(const Arg& lhs, T rhs) {
    return false;
  }

  friend bool operator!=(const Arg& lhs, T rhs);
};
template <typename T>
bool operator!=(const Arg<T>& lhs, T rhs) {
  return true;
}
bool foo() {
  Arg<int> arg;
  return (arg == 42) || (arg != 42);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions