1*07529996SIlya Biryukov // RUN: rm -rf %t 2*07529996SIlya Biryukov // RUN: mkdir %t 3*07529996SIlya Biryukov // RUN: split-file %s %t 4*07529996SIlya Biryukov // 5*07529996SIlya Biryukov // We need '-fmodules-local-submodule-visibility' to properly test merging when building a module from multiple 6*07529996SIlya Biryukov // headers inside the same TU. C++20 mode would imply this flag, but we need it to set it explicitly for C++14. 7*07529996SIlya Biryukov // 8*07529996SIlya Biryukov // RUN: %clang_cc1 -xc++ -std=c++14 -fmodules -fmodules-local-submodule-visibility -fmodule-name=library \ 9*07529996SIlya Biryukov // RUN: -emit-module %t/modules.map \ 10*07529996SIlya Biryukov // RUN: -o %t/module.pcm 11*07529996SIlya Biryukov // 12*07529996SIlya Biryukov // 13*07529996SIlya Biryukov // RUN: %clang_cc1 -xc++ -std=c++14 -fmodules -fmodules-local-submodule-visibility -fmodule-file=%t/module.pcm \ 14*07529996SIlya Biryukov // RUN: -fmodule-map-file=%t/modules.map \ 15*07529996SIlya Biryukov // RUN: -fsyntax-only -verify %t/use.cpp 16*07529996SIlya Biryukov // 17*07529996SIlya Biryukov //--- use.cpp 18*07529996SIlya Biryukov 19*07529996SIlya Biryukov #include "var1.h" 20*07529996SIlya Biryukov #include "var2.h" 21*07529996SIlya Biryukov 22*07529996SIlya Biryukov auto foo = zero<Int>; 23*07529996SIlya Biryukov auto bar = zero<int*>; 24*07529996SIlya Biryukov auto baz = zero<int>; 25*07529996SIlya Biryukov 26*07529996SIlya Biryukov template <class T> constexpr T zero = 0; // expected-error {{redefinition}} expected-note@* {{previous}} 27*07529996SIlya Biryukov template <> constexpr Int zero<Int> = {0}; // expected-error {{redefinition}} expected-note@* {{previous}} 28*07529996SIlya Biryukov template <class T> constexpr T* zero<T*> = nullptr; // expected-error {{redefinition}} expected-note@* {{previous}} 29*07529996SIlya Biryukov 30*07529996SIlya Biryukov template <> constexpr int** zero<int**> = nullptr; // ok, new specialization. 31*07529996SIlya Biryukov template <class T> constexpr T** zero<T**> = nullptr; // ok, new partial specilization. 32*07529996SIlya Biryukov 33*07529996SIlya Biryukov //--- modules.map 34*07529996SIlya Biryukov module "library" { 35*07529996SIlya Biryukov export * 36*07529996SIlya Biryukov module "var1" { 37*07529996SIlya Biryukov export * 38*07529996SIlya Biryukov header "var1.h" 39*07529996SIlya Biryukov } 40*07529996SIlya Biryukov module "var2" { 41*07529996SIlya Biryukov export * 42*07529996SIlya Biryukov header "var2.h" 43*07529996SIlya Biryukov } 44*07529996SIlya Biryukov } 45*07529996SIlya Biryukov 46*07529996SIlya Biryukov //--- var1.h 47*07529996SIlya Biryukov #ifndef VAR1_H 48*07529996SIlya Biryukov #define VAR1_H 49*07529996SIlya Biryukov 50*07529996SIlya Biryukov template <class T> constexpr T zero = 0; 51*07529996SIlya Biryukov struct Int { 52*07529996SIlya Biryukov int value; 53*07529996SIlya Biryukov }; 54*07529996SIlya Biryukov template <> constexpr int zero<Int> = {0}; 55*07529996SIlya Biryukov template <class T> constexpr T* zero<T*> = nullptr; 56*07529996SIlya Biryukov 57*07529996SIlya Biryukov #endif // VAR1_H 58*07529996SIlya Biryukov 59*07529996SIlya Biryukov //--- var2.h 60*07529996SIlya Biryukov #ifndef VAR2_H 61*07529996SIlya Biryukov #define VAR2_H 62*07529996SIlya Biryukov 63*07529996SIlya Biryukov template <class T> constexpr T zero = 0; 64*07529996SIlya Biryukov struct Int { 65*07529996SIlya Biryukov int value; 66*07529996SIlya Biryukov }; 67*07529996SIlya Biryukov template <> constexpr int zero<Int> = {0}; 68*07529996SIlya Biryukov template <class T> constexpr T* zero<T*> = nullptr; 69*07529996SIlya Biryukov 70*07529996SIlya Biryukov #endif // VAR2_H 71