| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: %clang_cc1 -x c++ -I %S/Inputs/redecl-templates %s -verify -std=c++14 |
| 3 |
// RUN: %clang_cc1 -x c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/redecl-templates %s -verify -std=c++14 |
| 4 |
|
| 5 |
template<int N> struct A {}; |
| 6 |
template<int N> using X = A<N>; |
| 7 |
|
| 8 |
template<int N> constexpr void f() {} |
| 9 |
template<int N> constexpr void g() { f<N>(); } |
| 10 |
|
| 11 |
template<int N> extern int v; |
| 12 |
template<int N> int &w = v<N>; |
| 13 |
|
| 14 |
#include "a.h" |
| 15 |
|
| 16 |
// Be careful not to mention A here, that'll import the decls from "a.h". |
| 17 |
int g(X<1> *); |
| 18 |
X<1> *p = 0; |
| 19 |
|
| 20 |
// This will implicitly instantiate A<1> if we haven't imported the explicit |
| 21 |
// specialization declaration from "a.h". |
| 22 |
int k = g(p); |
| 23 |
// Likewise for f and v. |
| 24 |
void h() { g<1>(); } |
| 25 |
int &x = w<1>; |
| 26 |
|
| 27 |
// This is OK: we declared the explicit specialization before we triggered |
| 28 |
// instantiation of this specialization. |
| 29 |
template<> struct A<1> {}; |
| 30 |
template<> constexpr void f<1>() {} |
| 31 |
// Variable template explicit specializations are always definitions unless they |
| 32 |
// are static data members declared without an initializer. |
| 33 |
template<> int v<1>; // expected-error {{redefinition of 'v<1>'}} |
| 34 |
// expected-note@Inputs/redecl-templates/a.h:8 {{previous definition is here}} |