Skip to content

[c++][Modules] Member variable of non-exported type has inaccessible hidden friend with defaulted comparison #123815

@davidstone

Description

@davidstone

The following valid translation units

export module a;

namespace n {
}
export module b;

import a;

namespace n {

struct monostate {
	friend bool operator==(monostate, monostate) = default;
};

export struct wrapper {
	friend bool operator==(wrapper const &, wrapper const &) = default;

	monostate m_value;
};

} // namespace n
import b;

static_assert(n::wrapper() == n::wrapper());

are rejected by clang with

In file included from /app/c.cpp:1:
b.cpp:12:67: error: invalid operands to binary expression ('const monostate' and 'const monostate')
   12 |         friend bool operator==(wrapper const &, wrapper const &) = default;
      |                                                                          ^
c.cpp:3:28: note: in defaulted equality comparison operator for 'wrapper' first required here
    3 | static_assert(n::wrapper() == n::wrapper());
      |                            ^
c.cpp:3:28: error: static assertion expression is not an integral constant expression
    3 | static_assert(n::wrapper() == n::wrapper());
      |               ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
2 errors generated.

See it live: https://godbolt.org/z/19dG3G7Pb

Introduced by c5e4afe @ChuanqiXu9

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions