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