Skip to content

Commit 344d83f

Browse files
committed
Add test for as cast aggregate has no to_string overload
1 parent 93adf1b commit 344d83f

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+
std::variant<int, A>(42) as std::string;
3+
}
4+
5+
A: type = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
In file included from mixed-as-cast-aggregate-has-no-to_string-overload.cpp:6:
2+
../../../include/cpp2util.h:2167:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<std::string, std::variant<int, A>>' "One of aggregate types has no cpp2::to_string overload - if you're sure you want this, use `cpp2::to_string() to force the conversion"
3+
static_assert(
4+
^
5+
mixed-as-cast-aggregate-has-no-to_string-overload.cpp2:2:11: note: in instantiation of function template specialization 'cpp2::as_<std::string, std::variant<int, A>>' requested here
6+
cpp2::as_<std::string>(std::variant<int,A>(42));
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-aggregate-has-no-to_string-overload.cpp2"
9+
10+
#line 5 "mixed-as-cast-aggregate-has-no-to_string-overload.cpp2"
11+
class A;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
#line 1 "mixed-as-cast-aggregate-has-no-to_string-overload.cpp2"
17+
auto main() -> int;
18+
19+
#line 5 "mixed-as-cast-aggregate-has-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-aggregate-has-no-to_string-overload.cpp2"
26+
27+
28+
//=== Cpp2 function definitions =================================================
29+
30+
#line 1 "mixed-as-cast-aggregate-has-no-to_string-overload.cpp2"
31+
auto main() -> int{
32+
#line 2 "mixed-as-cast-aggregate-has-no-to_string-overload.cpp2"
33+
cpp2::as_<std::string>(std::variant<int,A>(42));
34+
}
35+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mixed-as-cast-aggregate-has-no-to_string-overload.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)