Skip to content

Commit 0722b8a

Browse files
authored
[Clang][NFC] Consolidate tests for default argument substitution (#105617)
Follow-up on 8ac140f. The test `SemaTemplate/default-parm-init.cpp` was introduced since the fix #80288 and mainly did the following things: - Ensure the default arguments are properly substituted inside either the primary template & their explicit / out-of-line specializations. - Ensure the strategy doesn't mess up the substitution of a lambda expression as a default argument. The 1st is for the bug of #68490, yet it does some redundant work: each of the member functions is duplicated twice for the `sizeof` and `alignof` operators, respectively, and the principle under the hood are essentially the same. So this patch removes the duplication and reduces the 8 functions to 4 functions that reveal the same thing. The 2nd is presumably testing that the fix in #80288 doesn't impact a complicated substitution. However, that seems unnecessary & unrelated to the original issue. And more importantly, we don't have any problems with that ever. Hence, I'll remove that test from this patch. The test for default arguments is merged into `SemaTemplate/default-arguments.cpp` with a new namespace, and hopefully this could reduce the entropy of our testing cases.
1 parent d6dc7cf commit 0722b8a

File tree

2 files changed

+52
-190
lines changed

2 files changed

+52
-190
lines changed

clang/test/SemaTemplate/default-arguments.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,55 @@ namespace unevaluated {
229229
template<int = 0> int f(int = a); // expected-warning 0-1{{extension}}
230230
int k = sizeof(f());
231231
}
232+
233+
#if __cplusplus >= 201103L
234+
namespace GH68490 {
235+
236+
template <typename T> struct S {
237+
template <typename U>
238+
constexpr int SizeOfU(int param = sizeof(U)) const;
239+
240+
template <typename U>
241+
constexpr int SizeOfT(int param = sizeof(T)) const;
242+
};
243+
244+
template <typename T> struct S<T *> {
245+
template <typename U>
246+
constexpr int SizeOfU(int param = sizeof(U)) const;
247+
248+
template <typename U>
249+
constexpr int SizeOfT(int param = sizeof(T *)) const;
250+
};
251+
252+
template <typename T>
253+
template <typename U>
254+
constexpr int S<T *>::SizeOfU(int param) const {
255+
return param;
256+
}
257+
258+
template <typename T>
259+
template <typename U>
260+
constexpr int S<T *>::SizeOfT(int param) const {
261+
return param;
262+
}
263+
264+
template <>
265+
template <typename T>
266+
constexpr int S<int>::SizeOfU(int param) const {
267+
return param;
268+
}
269+
270+
template <>
271+
template <typename T>
272+
constexpr int S<int>::SizeOfT(int param) const {
273+
return param;
274+
}
275+
276+
static_assert(S<int>().SizeOfU<char>() == sizeof(char), "");
277+
static_assert(S<int>().SizeOfT<char>() == sizeof(int), "");
278+
static_assert(S<short *>().SizeOfU<char>() == sizeof(char), "");
279+
static_assert(S<short *>().SizeOfT<char>() == sizeof(short *), "");
280+
281+
} // namespace GH68490
282+
283+
#endif

clang/test/SemaTemplate/default-parm-init.cpp

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)