35 lines · cpp
1// RUN: rm -rf %t2// RUN: %clang_cc1 -x c++ -I %S/Inputs/redecl-templates %s -verify -std=c++143// RUN: %clang_cc1 -x c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/redecl-templates %s -verify -std=c++144 5template<int N> struct A {};6template<int N> using X = A<N>;7 8template<int N> constexpr void f() {}9template<int N> constexpr void g() { f<N>(); }10 11template<int N> extern int v;12template<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".17int g(X<1> *);18X<1> *p = 0;19 20// This will implicitly instantiate A<1> if we haven't imported the explicit21// specialization declaration from "a.h".22int k = g(p);23// Likewise for f and v.24void h() { g<1>(); }25int &x = w<1>;26 27// This is OK: we declared the explicit specialization before we triggered28// instantiation of this specialization.29template<> struct A<1> {};30template<> constexpr void f<1>() {}31// Variable template explicit specializations are always definitions unless they32// are static data members declared without an initializer.33template<> int v<1>; // expected-error {{redefinition of 'v<1>'}}34 // expected-note@Inputs/redecl-templates/a.h:8 {{previous definition is here}}35