Skip to content

Commit 16174b3

Browse files
committed
feat: allow template specialization
1 parent 387d352 commit 16174b3

13 files changed

+120
-7
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
t: @struct <T: type> type = {
2+
a: i32 = 1;
3+
}
4+
t: @struct <T: type> specialize<T> type requires std::is_void_v<T> = {
5+
b: i32 = 2;
6+
}
7+
t: @struct specialize<i64> type = {
8+
c: i32 = 3;
9+
}
10+
v: <T> const i32 = 1;
11+
v: <> specialize<void> const i32 = 2;
12+
main: () = {
13+
[[assert Testing: t<i32>().a == 1]]
14+
[[assert Testing: t<void>().b == 2]]
15+
[[assert Testing: t<i64>().c == 3]]
16+
[[assert Testing: (v<i32>) == 1]]
17+
[[assert Testing: (v<void>) == 2]]
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 3723ede3cf5324827f8fbbe7f484c2ee4d7a7204)
2+
Target: x86_64-pc-linux-gnu
3+
Thread model: posix
4+
InstalledDir: /home/johel/root/clang-main/bin

regression-tests/test-results/clang-18/pure2-bugfix-for-non-local-function-expression.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-non-local-function-expression.cpp.output

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-print.cpp.output

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-template-specialization.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-template-specialization.cpp.output

Whitespace-only changes.

regression-tests/test-results/gcc-13/pure2-template-specialization.cpp.execution

Whitespace-only changes.

regression-tests/test-results/gcc-13/pure2-template-specialization.cpp.output

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
template<typename T> class t;
10+
11+
12+
//=== Cpp2 type definitions and function declarations ===========================
13+
14+
template<typename T> class t {
15+
public: cpp2::i32 a {1};
16+
};
17+
template<typename T> requires( std::is_void_v<T> )
18+
class t<T> {public: cpp2::i32 b {2};
19+
};
20+
template<> class t<cpp2::i64> {
21+
public: cpp2::i32 c {3};
22+
};
23+
template<typename T> extern cpp2::i32 const v;
24+
25+
auto main() -> int;
26+
27+
28+
//=== Cpp2 function definitions =================================================
29+
30+
31+
#line 10 "pure2-template-specialization.cpp2"
32+
template<typename T> cpp2::i32 const v {1};
33+
template<> cpp2::i32 const v<void> {2};
34+
auto main() -> int{
35+
cpp2::Testing.expects(t<cpp2::i32>().a == 1, "");
36+
cpp2::Testing.expects(t<void>().b == 2, "");
37+
cpp2::Testing.expects(t<cpp2::i64>().c == 3, "");
38+
cpp2::Testing.expects((v<cpp2::i32>) == 1, "");
39+
cpp2::Testing.expects((v<void>) == 2, "");
40+
}
41+

0 commit comments

Comments
 (0)