brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 2b7fa78 Raw
115 lines · cpp
1// The test is check we couldn't export a redeclaration which isn't exported previously and2// check it is OK to redeclare no matter exported nor not if is the previous declaration is exported.3// RUN: %clang_cc1 -std=c++20 %s -verify4 5export module X;6 7struct S { // expected-note {{previous declaration is here}}8  int n;9};10typedef S S;11export typedef S S; // OK, does not redeclare an entity12export struct S;    // expected-error {{cannot export redeclaration 'S' here since the previous declaration has module linkage}}13 14namespace A {15struct X; // expected-note {{previous declaration is here}}16export struct Y;17} // namespace A18 19namespace A {20export struct X; // expected-error {{cannot export redeclaration 'X' here since the previous declaration has module linkage}}21export struct Y; // OK22struct Z;        // expected-note {{previous declaration is here}}23export struct Z; // expected-error {{cannot export redeclaration 'Z' here since the previous declaration has module linkage}}24} // namespace A25 26namespace A {27struct B;    // expected-note {{previous declaration is here}}28struct C {}; // expected-note {{previous declaration is here}}29} // namespace A30 31namespace A {32export struct B {}; // expected-error {{cannot export redeclaration 'B' here since the previous declaration has module linkage}}33export struct C;    // expected-error {{cannot export redeclaration 'C' here since the previous declaration has module linkage}}34} // namespace A35 36template <typename T>37struct TemplS; // expected-note {{previous declaration is here}}38 39export template <typename T>40struct TemplS {}; // expected-error {{cannot export redeclaration 'TemplS' here since the previous declaration has module linkage}}41 42template <typename T>43struct TemplS2; // expected-note {{previous declaration is here}}44 45export template <typename U>46struct TemplS2 {}; // expected-error {{cannot export redeclaration 'TemplS2' here since the previous declaration has module linkage}}47 48void baz();        // expected-note {{previous declaration is here}}49export void baz(); // expected-error {{cannot export redeclaration 'baz' here since the previous declaration has module linkage}}50 51namespace A {52export void foo();53void bar();        // expected-note {{previous declaration is here}}54export void bar(); // expected-error {{cannot export redeclaration 'bar' here since the previous declaration has module linkage}}55void f1();         // expected-note {{previous declaration is here}}56} // namespace A57 58// OK59//60// [module.interface]/p661// A redeclaration of an entity X is implicitly exported if X was introduced by an exported declaration62void A::foo();63 64// The compiler couldn't export A::f1() here since A::f1() is declared above without exported.65// See [module.interface]/p6 for details.66export void A::f1(); // expected-error {{cannot export redeclaration 'f1' here since the previous declaration has module linkage}}67 68template <typename T>69void TemplFunc(); // expected-note {{previous declaration is here}}70 71export template <typename T>72void TemplFunc() { // expected-error {{cannot export redeclaration 'TemplFunc' here since the previous declaration has module linkage}}73}74 75namespace A {76template <typename T>77void TemplFunc2(); // expected-note {{previous declaration is here}}78export template <typename T>79void TemplFunc2() {} // expected-error {{cannot export redeclaration 'TemplFunc2' here since the previous declaration has module linkage}}80template <typename T>81void TemplFunc3(); // expected-note {{previous declaration is here}}82} // namespace A83 84export template <typename T>85void A::TemplFunc3() {} // expected-error {{cannot export redeclaration 'TemplFunc3' here since the previous declaration has module linkage}}86 87int var;        // expected-note {{previous declaration is here}}88export int var; // expected-error {{cannot export redeclaration 'var' here since the previous declaration has module linkage}}89 90template <typename T>91T TemplVar; // expected-note {{previous declaration is here}}92export template <typename T>93T TemplVar; // expected-error {{cannot export redeclaration 'TemplVar' here since the previous declaration has module linkage}}94 95// Test the compiler wouldn't complain about the redeclaration of friend in exported class.96namespace Friend {97template <typename T>98class bar;99class gua;100template <typename T>101void hello();102void hi();103export class foo;104bool operator<(const foo &a, const foo &b);105export class foo {106  template <typename T>107  friend class bar;108  friend class gua;109  template <typename T>110  friend void hello();111  friend void hi();112  friend bool operator<(const foo &a, const foo &b);113};114} // namespace Friend115