Skip to content

[Clang][C++] Better error message for defining a friend function in a local class defintion #116808

@dawmd

Description

@dawmd

Reproducer:

void f() {
    struct A {
        friend void foo() {}
    };
}

compiled with --std=gnu++23.


clang-19.1.0:

<source>:3:21: error: no matching function found in local scope
    3 |         friend void foo() {}
      |                     ^~~
1 error generated.

gcc-14-2:

<source>: In function 'void f()':
<source>:3:21: error: cannot define friend function 'foo' in a local class definition
    3 |         friend void foo() {}
      |                     ^~~

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzergood first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions