
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.
84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
// 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
|