Skip to content

Commit 93adf1b

Browse files
committed
Add test for as cast to string with no to_string overload
1 parent 5864973 commit 93adf1b

4 files changed

+50
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
main: () = {
2+
A() as std::string;
3+
}
4+
5+
A: type = {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
In file included from mixed-as-cast-no-to_string-overload.cpp:6:
2+
../../../include/cpp2util.h:2163:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<std::string, A>' "No cpp2::to_string overload exists for this type!"
3+
static_assert(
4+
^
5+
mixed-as-cast-no-to_string-overload.cpp2:2:11: note: in instantiation of function template specialization 'cpp2::as_<std::string, A>' requested here
6+
cpp2::as_<std::string>(A());
7+
^
8+
1 error generated.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
//=== Cpp2 type declarations ====================================================
4+
5+
6+
#include "cpp2util.h"
7+
8+
#line 1 "mixed-as-cast-no-to_string-overload.cpp2"
9+
10+
#line 5 "mixed-as-cast-no-to_string-overload.cpp2"
11+
class A;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
#line 1 "mixed-as-cast-no-to_string-overload.cpp2"
17+
auto main() -> int;
18+
19+
#line 5 "mixed-as-cast-no-to_string-overload.cpp2"
20+
class A {
21+
public: A() = default;
22+
public: A(A const&) = delete; /* No 'that' constructor, suppress copy */
23+
public: auto operator=(A const&) -> void = delete;
24+
};
25+
#line 6 "mixed-as-cast-no-to_string-overload.cpp2"
26+
27+
28+
//=== Cpp2 function definitions =================================================
29+
30+
#line 1 "mixed-as-cast-no-to_string-overload.cpp2"
31+
auto main() -> int{
32+
#line 2 "mixed-as-cast-no-to_string-overload.cpp2"
33+
cpp2::as_<std::string>(A());
34+
}
35+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mixed-as-cast-no-to_string-overload.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)