[C++20] [Modules] Make the linkage consistent for template and its
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 23 Feb 2022 08:23:26 +0000 (16:23 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Thu, 24 Mar 2022 02:24:14 +0000 (10:24 +0800)
commit84746686088799ec9e3cc5ea0a64df81423da290
treea56f82c2bbfb1cf41fd3cdfbe16585856de0b93e
parentd7afea9eb84274a4c5046253f4d78a8fdd262803
[C++20] [Modules] Make the linkage consistent for template and its
specialization

Before the patch, the compiler would crash for the test due to
inconsistent linkage.

This patch tries to avoid it by make the linkage consistent for template
and its specialization. After the patch, the behavior of compiler would
be partially correct for the case.
The correct one is:

```
export template<class T>
void f() {}

template<>
void f<int>() {}
```

In this case, the linkage for both declaration should be external (the
wording I get by consulting in WG21 is "the linkage for name f should be
external").

And for the case:
```
template<class T>
void f() {}

export template<>
void f<int>() {}
```

Compiler should reject it. This isn't done now. After all, this patch would
stop a crash.

Reviewed By: iains, aaron.ballman, dblaikie

Differential Revision: https://reviews.llvm.org/D120397
clang/lib/AST/Decl.cpp
clang/unittests/AST/DeclTest.cpp