[flang][cuda] Do not register global constants (#118582)
[llvm-project.git] / clang / test / Modules / redundant-template-default-arg3.cpp
blobda6fe01a5357bf589169dcc52b3bd224e36aad75
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
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
11 //--- foo.h
12 template <typename T = int>
13 T v;
15 template <int T = 8>
16 int v2;
18 template <typename T>
19 class my_array {};
21 template <template <typename> typename C = my_array>
22 int v3;
24 template <typename T, int *i = nullptr>
25 T v4;
27 template <typename T, T *i = nullptr>
28 T v5;
30 inline int a = 43;
31 template <typename T, int *i = &a>
32 T v6;
34 inline int b = 43;
35 template <typename T, T *i = &b>
36 T v7;
38 template <int T = (3 > 2)>
39 int v8;
41 consteval int getInt() {
42 return 55;
44 template <int T = getInt()>
45 int v9;
47 //--- foo_bad.h
48 template <typename T = double>
49 T v;
51 template <int T = 9>
52 int v2;
54 template <typename T>
55 class others_array {};
57 template <template <typename> typename C = others_array>
58 int v3;
60 static int a;
61 consteval int *getIntPtr() {
62 return &a;
64 template <typename T, int *i = getIntPtr()>
65 T v4;
67 consteval void *getVoidPtr() {
68 return &a;
70 template <typename T, T *i = getVoidPtr()>
71 T v5;
73 inline int a_ = 43;
74 template <typename T, int *i = &a_>
75 T v6;
77 inline int b_ = 43;
78 template <typename T, T *i = &b_>
79 T v7;
81 template <int T = -1>
82 int v8;
84 consteval int getInt2() {
85 return 55;
87 template <int T = getInt2()>
88 int v9;
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;
105 //--- use.cpp
106 import foo;
107 #include "foo_bad.h"
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>}}