Skip to content

[C++20] [Modules] Diagnose exposure for TUlocal entity  #112294

@ChuanqiXu9

Description

@ChuanqiXu9

The wording is at http://eel.is/c++draft/basic.link#14

The simplest example is:

export module a;
static int a = 43;
export inline int func() {
    return a;
}

According to the spec, we should reject the example and say “the TU-local entity ‘a’ is an exposure”. But we didn’t implement this. We would accept the example silently. The practical affect this is, user may get weird diagnostic informations triggered by other places. Or, in the worst case, they may get runtime errors if the static variable have dyanmic initializers.

The reason why I didn’t implement this is, to implement this now, we may need to implement something more complex than the existing mechanism for used information in Sema. I feel it is too complex. So I feel maybe we can implement it in Serializer, not in Sema. The idea is, if we write anythiing internal to the current TU to the BMI, we can issue a diagnostic. But it requires we make the reduced BMI (https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi) the default. Since the current full BMI will contain the full information after all. And according to my plan, the reduced BMI will be the default in clang21. So this feature is expected to be implemented that time.


Update: delayed to clang22.

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