1 // RUN: rm -rf %t
2 // RUN: mkdir %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1  -std=c++20 %t/foo.cppm -I%t -emit-module-interface -o %t/foo.pcm
6 // RUN: %clang_cc1  -fprebuilt-module-path=%t -std=c++20 %t/use.cpp -I%t/. -fsyntax-only -verify
7 
8 //--- foo.h
9 template <typename T = int>
10 T v;
11 
12 template <int T = 8>
13 int v2;
14 
15 template <typename T>
16 class my_array {};
17 
18 template <template <typename> typename C = my_array>
19 int v3;
20 
21 template <typename T, int *i = nullptr>
22 T v4;
23 
24 template <typename T, T *i = nullptr>
25 T v5;
26 
27 inline int a = 43;
28 template <typename T, int *i = &a>
29 T v6;
30 
31 inline int b = 43;
32 template <typename T, T *i = &b>
33 T v7;
34 
35 template <int T = (3 > 2)>
36 int v8;
37 
getInt()38 consteval int getInt() {
39   return 55;
40 }
41 template <int T = getInt()>
42 int v9;
43 
44 //--- foo_bad.h
45 template <typename T = double>
46 T v;
47 
48 template <int T = 9>
49 int v2;
50 
51 template <typename T>
52 class others_array {};
53 
54 template <template <typename> typename C = others_array>
55 int v3;
56 
57 static int a;
getIntPtr()58 consteval int *getIntPtr() {
59   return &a;
60 }
61 template <typename T, int *i = getIntPtr()>
62 T v4;
63 
getVoidPtr()64 consteval void *getVoidPtr() {
65   return &a;
66 }
67 template <typename T, T *i = getVoidPtr()>
68 T v5;
69 
70 inline int a_ = 43;
71 template <typename T, int *i = &a_>
72 T v6;
73 
74 inline int b_ = 43;
75 template <typename T, T *i = &b_>
76 T v7;
77 
78 template <int T = -1>
79 int v8;
80 
getInt2()81 consteval int getInt2() {
82   return 55;
83 }
84 template <int T = getInt2()>
85 int v9;
86 
87 //--- foo.cppm
88 module;
89 #include "foo.h"
90 export module foo;
91 
92 //--- use.cpp
93 import foo;
94 #include "foo_bad.h"
95 
96 // expected-error@foo_bad.h:1 {{template parameter default argument is inconsistent with previous definition}}
97 // [email protected]:1 {{previous default template argument defined in module foo.<global>}}
98 // expected-error@foo_bad.h:4 {{template parameter default argument is inconsistent with previous definition}}
99 // [email protected]:4 {{previous default template argument defined in module foo.<global>}}
100 // expected-error@foo_bad.h:10 {{template parameter default argument is inconsistent with previous definition}}
101 // [email protected]:10 {{previous default template argument defined in module foo.<global>}}
102 // expected-error@foo_bad.h:17 {{template parameter default argument is inconsistent with previous definition}}
103 // [email protected]:13 {{previous default template argument defined in module foo.<global>}}
104 // expected-error@foo_bad.h:23 {{template parameter default argument is inconsistent with previous definition}}
105 // [email protected]:16 {{previous default template argument defined in module foo.<global>}}
106 // expected-error@foo_bad.h:27 {{template parameter default argument is inconsistent with previous definition}}
107 // [email protected]:20 {{previous default template argument defined in module foo.<global>}}
108 // expected-error@foo_bad.h:31 {{template parameter default argument is inconsistent with previous definition}}
109 // [email protected]:24 {{previous default template argument defined in module foo.<global>}}
110 // expected-error@foo_bad.h:34 {{template parameter default argument is inconsistent with previous definition}}
111 // [email protected]:27 {{previous default template argument defined in module foo.<global>}}
112 // expected-error@foo_bad.h:40 {{template parameter default argument is inconsistent with previous definition}}
113 // [email protected]:33 {{previous default template argument defined in module foo.<global>}}
114