Skip to content

Clang-trunk rejects valid friend declaration of private base class with very confusing diagnostic #121258

@wangbo15

Description

@wangbo15

The following code is rejected by clang-trunk:

struct payload {};

struct base: private payload {
};

struct derived: base {
    friend class payload;
};

The diagnostic is hard to understand. It seems the compiler treats the private inheritance statement as a member declaration or something else here:

<source>:7:18: error: 'payload' is a private member of 'payload'
    7 |     friend class payload;
      |                  ^
<source>:3:14: note: constrained by private inheritance here
    3 | struct base: private payload {
      |              ^~~~~~~~~~~~~~~
<source>:1:8: note: member is declared here
    1 | struct payload {};
      |        ^
1 error generated.

GCC and MSVC both accept it.

Please see https://godbolt.org/z/4da5TbvYe

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerdiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions