<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/112294>112294</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] Diagnose exposure for TUlocal entity 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:modules
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ChuanqiXu9
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VVFv4zYM_jXKC1HDUZImechD0yzAPRw2oD1sr7REx9rJUk6im8t-_UDZadPDMKB1bFH6SH78SGHO7hSIdmq1V6vDDAfuYto9dwOGH-6vYTtror3uXjuCS0zWhRO4DMjQMZ_V4knpo9JHIl-5rPTRKL1Xem8Ttqz0scHsTOVd-K70Yr5U9UHVT-NTELPrz54yA_1EeQOXBfJul3qsp7_yST_PMTH00Q6eANViP65nRnYGXGBAUIsDLBfvtumMC94FKlvaIRilN0pvQa2nXQAAiXhI4Q5WrQ__Gcb4fDJmYoQjsKRzJqP0M1wIchc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