Skip to content

Commit 8823a7e

Browse files
committed
[NFC] [clang] add tests for merging of UsingShadowDecl
1 parent 10a55ca commit 8823a7e

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

clang/test/Modules/GH80252.cppm

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: cd %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o %t/A.pcm -verify
6+
// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cppm -emit-module-interface -o %t/B.pcm -verify
7+
// RUN: %clang_cc1 -std=c++20 -I %t %t/C.cpp -fmodule-file=A=%t/A.pcm -fmodule-file=B=%t/B.pcm -fsyntax-only -verify
8+
9+
//--- foo.h
10+
namespace baz {
11+
using foo = char;
12+
using baz::foo;
13+
}
14+
15+
//--- bar.h
16+
class bar {
17+
bar(baz::foo);
18+
};
19+
20+
//--- A.cppm
21+
// expected-no-diagnostics
22+
module;
23+
#include "foo.h"
24+
export module A;
25+
26+
//--- B.cppm
27+
// expected-no-diagnostics
28+
module;
29+
#include "foo.h"
30+
#include "bar.h"
31+
export module B;
32+
33+
//--- C.cpp
34+
#include "foo.h"
35+
import A;
36+
#include "bar.h"
37+
import B;
38+
// Since modules are loaded lazily, force loading by performing a lookup.
39+
using xxx = bar;
40+
// FIXME: This is a false positive ODR violation.
41+
// [email protected]:2 {{'bar' has different definitions in different modules; first difference is defined here found constructor with 1st parameter of type 'baz::foo' (aka 'char')}}
42+
// [email protected]:2 {{but in 'B.<global>' found constructor with 1st parameter of type 'baz::foo' (aka 'char')}}

clang/test/Modules/cxx20-decls.cppm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: cd %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o %t/A.pcm -verify
6+
// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm -fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
7+
8+
//--- foo.h
9+
namespace baz {
10+
using foo = char;
11+
using baz::foo;
12+
}
13+
14+
//--- A.cppm
15+
// expected-no-diagnostics
16+
module;
17+
#include "foo.h"
18+
export module A;
19+
20+
//--- B.cpp
21+
// expected-no-diagnostics
22+
#include "foo.h"
23+
import A;
24+
// Since modules are loaded lazily, force loading by performing a lookup.
25+
using xxx = baz::foo;
26+
27+
// CHECK-LABEL: Dumping baz:
28+
// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ ]*]] <{{.*}}> line:{{.*}} imported in A.<global> hidden <undeserialized declarations> baz
29+
// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
30+
// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden foo 'char'
31+
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
32+
// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden baz::foo
33+
// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
34+
// FIXME: UsingShadowDecl should have been merged
35+
// CHECK-NOT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
36+
// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
37+
38+
// CHECK-LABEL: Dumping baz:
39+
// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
40+
// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced foo 'char'
41+
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
42+
// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
43+
// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
44+
// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

0 commit comments

Comments
 (0)