llvm / llvm/llvm-project

`Wmissing-prototypes` and `Wmissing-variable-declarations` should not trigger in a module

Open
#192,996 14 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics clang:modules false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following translation unit

```c++
export module m;

void f() {
}

int x;
```

when compiled with `clang++ -std=c++20 -Wmissing-prototypes -Wmissing-variable-declarations` gives a warning of

```console
:3:6: warning: no previous prototype for function 'f' [-Wmissing-prototypes]
3 | void f() {
| ^
:3:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
3 | void f() {
| ^
| static
:6:5: warning: no previous extern declaration for non-static variable 'x' [-Wmissing-variable-declarations]
6 | int x;
| ^
:6:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit
6 | int x;
| ^
2 warnings generated.
Compiler returned: 0
```

The purpose of these warnings is to prevent violations of the one-definition rule. Modules already prevent this problem because the function is defined in the module purview, so no warning is needed in these cases.

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

Contributor guide

Open the contributing guide

Research direction

Reproduce the warning with clang++ using the C++20 module translation unit and both warning flags shown in the issue. Trace how diagnostics are emitted for declarations in a module purview; done means f and x no longer trigger these warnings there while the warnings remain applicable in non-module translation units.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.