[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / merge-var-template-spec.cpp
blob01448f34e6338538fafdb5d0b1ca7caba5af1578
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
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
17 //--- use.cpp
19 #include "var1.h"
20 #include "var2.h"
22 auto foo = zero<Int>;
23 auto bar = zero<int*>;
24 auto baz = zero<int>;
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}}
30 template <> constexpr int** zero<int**> = nullptr; // ok, new specialization.
31 template <class T> constexpr T** zero<T**> = nullptr; // ok, new partial specilization.
33 //--- modules.map
34 module "library" {
35 export *
36 module "var1" {
37 export *
38 header "var1.h"
40 module "var2" {
41 export *
42 header "var2.h"
46 //--- var1.h
47 #ifndef VAR1_H
48 #define VAR1_H
50 template <class T> constexpr T zero = 0;
51 struct Int {
52 int value;
54 template <> constexpr int zero<Int> = {0};
55 template <class T> constexpr T* zero<T*> = nullptr;
57 #endif // VAR1_H
59 //--- var2.h
60 #ifndef VAR2_H
61 #define VAR2_H
63 template <class T> constexpr T zero = 0;
64 struct Int {
65 int value;
67 template <> constexpr int zero<Int> = {0};
68 template <class T> constexpr T* zero<T*> = nullptr;
70 #endif // VAR2_H