[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 13 07:20:42 PDT 2024


jyknight wrote:

To get back to my previous point about the semantics implemented by this patch being unfortunate -- the upshot is that, now:
```
#include <assert.h>
#define NDEBUG
#import <assert.h>
```
will include assert.h twice (even though the latter is an "import") _only_ if modules are enabled. If modules are disabled, import keeps the original behavior of suppressing multiple inclusion. This doesn't make sense: with modules disabled, everything is textual -- to say that "textual header" in a modulemap should make a header somehow "more" textual than the default non-modular behavior is weird.

That is what I meant by my previous comment that this change has tied together features which should not be related -- and that's the main reason why I believe this PR should be reverted.

If we _do_ need to implement a behavior of suppressing `#import`'s include-once behavior for certain headers, it should be based on something within the header being included. E.g. could create a new`#pragma multiply_include_even_with_import` and add it to assert.h -- this would be effectively the reverse of `#pragma once`. I do not believe it's really needed (once the "header is hidden entirely" bug is fixed), but it would be consistent and not produce broken/surprising semantics.

https://github.com/llvm/llvm-project/pull/83660


More information about the cfe-commits mailing list