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