Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rnk opened this issue Apr 25, 2015 · 0 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@rnk
Copy link
Collaborator

rnk commented Apr 25, 2015

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);
}
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

1 participant