Skip to content

[Clang] Friend function reported to be undeclared unless one of the arguments is the class type #60524

@ShawnZhong

Description

@ShawnZhong

In the example below, foo is reported to be undeclared unless one of the arguments is the class type.

struct S {
  friend void foo(){};
  friend void foo(void*){};
  friend void foo(void*, void*){};
};

void test() {
  foo();  // use of undeclared identifier 'foo'

  foo(nullptr);      // use of undeclared identifier 'foo'
  foo((S*)nullptr);  // no error

  foo(nullptr, nullptr);          // use of undeclared identifier 'foo'
  foo((S*)nullptr, nullptr);      // no error
  foo(nullptr, (S*)nullptr);      // no error
  foo((S*)nullptr, (S*)nullptr);  // no error
}

I think that in all the cases, foo should be declared (and also defined), so the program should be valid.
https://eel.is/c++draft/class.friend#example-6 provides an example of defining friend function within the class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions