71 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir %t3// RUN: split-file %s %t4//5// We need '-fmodules-local-submodule-visibility' to properly test merging when building a module from multiple6// 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.pcm11//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.cpp16//17//--- use.cpp18 19#include "var1.h"20#include "var2.h"21 22auto foo = zero<Int>;23auto bar = zero<int*>;24auto baz = zero<int>;25 26template <class T> constexpr T zero = 0; // expected-error {{redefinition}} expected-note@* {{previous}}27template <> constexpr Int zero<Int> = {0}; // expected-error {{redefinition}} expected-note@* {{previous}}28template <class T> constexpr T* zero<T*> = nullptr; // expected-error {{redefinition}} expected-note@* {{previous}}29 30template <> constexpr int** zero<int**> = nullptr; // ok, new specialization.31template <class T> constexpr T** zero<T**> = nullptr; // ok, new partial specilization.32 33//--- modules.map34module "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.h47#ifndef VAR1_H48#define VAR1_H49 50template <class T> constexpr T zero = 0;51struct Int {52 int value;53};54template <> constexpr int zero<Int> = {0};55template <class T> constexpr T* zero<T*> = nullptr;56 57#endif // VAR1_H58 59//--- var2.h60#ifndef VAR2_H61#define VAR2_H62 63template <class T> constexpr T zero = 0;64struct Int {65 int value;66};67template <> constexpr int zero<Int> = {0};68template <class T> constexpr T* zero<T*> = nullptr;69 70#endif // VAR2_H71