-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++20] [Modules] Warn for duplicated decls in mutliple module units (#…
…105799) It is a long standing issue that the duplicated declarations in multiple module units would cause the compilation performance to get slowed down. And there are many questions or issue reports. So I think it is better to add a warning for it. And given this is not because the users' code violates the language specification or any best practices, the warning is disabled by default even if `-Wall` is specified. The users need to specify the warning explcitly or use `Weverything`. The documentation will add separately.
- Loading branch information
1 parent
cf6cd1f
commit 3cca522
Showing
5 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
clang/test/Modules/warn-duplicated-decls-in-module-units.cppm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -emit-module-interface -o %t/m1.pcm | ||
// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -emit-module-interface -o %t/m2.pcm | ||
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \ | ||
// RUN: -verify | ||
// | ||
// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -Wall -emit-module-interface -o %t/m1.pcm | ||
// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -Wall -emit-module-interface -o %t/m2.pcm | ||
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \ | ||
// RUN: -verify -Wall | ||
// | ||
// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -Wdecls-in-multiple-modules -emit-module-interface -o %t/m1.pcm | ||
// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -Wdecls-in-multiple-modules -emit-module-interface -o %t/m2.pcm | ||
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \ | ||
// RUN: -verify -Wdecls-in-multiple-modules -DWARNING | ||
|
||
//--- foo.h | ||
#ifndef FOO_H | ||
#define FOO_H | ||
|
||
enum E { E1, E2 }; | ||
|
||
int a = 43; | ||
|
||
class foo { | ||
public: | ||
void consume(E, int); | ||
}; | ||
|
||
inline void func() {} | ||
|
||
void fwd_decl(); | ||
|
||
#endif | ||
|
||
//--- m1.cppm | ||
module; | ||
#include "foo.h" | ||
export module m1; | ||
export { | ||
using ::foo; | ||
using ::a; | ||
using ::func; | ||
using ::fwd_decl; | ||
using ::E; | ||
} | ||
|
||
//--- m2.cppm | ||
module; | ||
#include "foo.h" | ||
export module m2; | ||
export { | ||
using ::foo; | ||
using ::a; | ||
using ::func; | ||
using ::fwd_decl; | ||
using ::E; | ||
} | ||
|
||
//--- use.cc | ||
import m1; | ||
import m2; | ||
void use(); | ||
void use() { | ||
E e = E1; | ||
foo f; | ||
f.consume(e, a); | ||
func(); | ||
fwd_decl(); | ||
} | ||
|
||
#ifndef WARNING | ||
// expected-no-diagnostics | ||
#else | ||
// expected-warning@* {{declaration 'E' is detected to be defined in multiple module units}} | ||
// expected-warning@* {{declaration 'foo' is detected to be defined in multiple module units}} | ||
// expected-warning@* {{declaration 'a' is detected to be defined in multiple module units}} | ||
// expected-warning@* {{declaration 'func' is detected to be defined in multiple module units}} | ||
// expected-note@* 1+ {{}} | ||
#endif |