llvm / llvm/llvm-project

[C++20] [Modules] Maybe confusing diagnostics for suggesting #include for header in module file

Open
#184,542 1 comment 0 reactions 1 assignee Claimed by @ChuanqiXu9 View on GitHub
clang:modules
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Minmal Reproducer:

```C++
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++23 %t/mod.cppm -emit-reduced-module-interface -o %t/mod.pcm
// RUN: %clang_cc1 -std=c++23 %t/user.cpp -fprebuilt-module-path=%t -verify -fsyntax-only

//--- header.h
#ifndef HEADER_H
#define HEADER_H

inline void foo() {}
// Make sure foo() won't be optimized out.
inline void bar() { foo(); }

#endif

//--- mod.cppm
module;
#include "header.h"
export module mod;
export using ::bar;

//--- user.cpp
import mod;
void test() {
foo(); // Suggests: missing '#include "header.h"';
}
```

The compiler said "missing #include". Not wrong. This is the reason why I didn't fix this for a long time. And also, for the past few years, I didn't heard a user complaining this to me.

But, when coding with AI, I told AI to use import. AI did. But compilation fails and clang said "missing #include". Then AI switches to #include smartly. But this is not what I want.

After all, in the new AI era, the diagnostic are much more important. All of us agree and believe diagnostic are important. But it shows it is more important than we thought.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.