Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / redundant-template-default-arg3.cpp
blob8bb222ac91ffce1f491c7cba55c3eab3bbe96c29
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 //--- foo.h
9 template <typename T = int>
10 T v;
12 template <int T = 8>
13 int v2;
15 template <typename T>
16 class my_array {};
18 template <template <typename> typename C = my_array>
19 int v3;
21 template <typename T, int *i = nullptr>
22 T v4;
24 template <typename T, T *i = nullptr>
25 T v5;
27 inline int a = 43;
28 template <typename T, int *i = &a>
29 T v6;
31 inline int b = 43;
32 template <typename T, T *i = &b>
33 T v7;
35 template <int T = (3 > 2)>
36 int v8;
38 consteval int getInt() {
39 return 55;
41 template <int T = getInt()>
42 int v9;
44 //--- foo_bad.h
45 template <typename T = double>
46 T v;
48 template <int T = 9>
49 int v2;
51 template <typename T>
52 class others_array {};
54 template <template <typename> typename C = others_array>
55 int v3;
57 static int a;
58 consteval int *getIntPtr() {
59 return &a;
61 template <typename T, int *i = getIntPtr()>
62 T v4;
64 consteval void *getVoidPtr() {
65 return &a;
67 template <typename T, T *i = getVoidPtr()>
68 T v5;
70 inline int a_ = 43;
71 template <typename T, int *i = &a_>
72 T v6;
74 inline int b_ = 43;
75 template <typename T, T *i = &b_>
76 T v7;
78 template <int T = -1>
79 int v8;
81 consteval int getInt2() {
82 return 55;
84 template <int T = getInt2()>
85 int v9;
87 //--- foo.cppm
88 module;
89 #include "foo.h"
90 export module foo;
92 //--- use.cpp
93 import foo;
94 #include "foo_bad.h"
96 // expected-error@foo_bad.h:1 {{template parameter default argument is inconsistent with previous definition}}
97 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h: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 // expected-note@foo.h:33 {{previous default template argument defined in module foo.<global>}}