Skip to content

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

@davidstone

Description

@davidstone

The following two valid translation units

export module a;

namespace n {

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

export struct a {
	friend auto operator==(a, a) -> bool = default;
	monostate m;
};

} // namespace n
export module b;

import a;

namespace n {

auto b() -> void {
	a() == a();
}

} // namespace n

causes clang to fail to compile with

In file included from /app/b.cpp:3:
a.cpp:10:47: error: invalid operands to binary expression ('monostate' and 'monostate')
   10 |         friend auto operator==(a, a) -> bool = default;
      |                                                      ^
b.cpp:8:6: note: in defaulted equality comparison operator for 'a' first required here
    8 |         a() == a();
      |             ^
b.cpp:8:6: warning: equality comparison result unused [-Wunused-comparison]
    8 |         a() == a();
      |         ~~~~^~~~~~
1 warning and 1 error generated.

See it live: https://godbolt.org/z/TvWs7osPs

This is basically the same as #123815 except instead of qualifying the call site with the namespace of the outer type, we are calling from within the namespace. This feels somewhat similar to but not the same as #133720

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