From 263915832993dd12beee10e204f9ebcc6c786ed2 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 30 Dec 2023 23:39:37 +0100 Subject: Meta: initial commit of WestCo optimized toolchain. Signed-off-by: Amlal El Mahrouss --- .../mixed-initialization-safety-1-error.cpp2 | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 CompilerDriver/cc2/regression-tests/mixed-initialization-safety-1-error.cpp2 (limited to 'CompilerDriver/cc2/regression-tests/mixed-initialization-safety-1-error.cpp2') diff --git a/CompilerDriver/cc2/regression-tests/mixed-initialization-safety-1-error.cpp2 b/CompilerDriver/cc2/regression-tests/mixed-initialization-safety-1-error.cpp2 new file mode 100644 index 0000000..e3d9bcd --- /dev/null +++ b/CompilerDriver/cc2/regression-tests/mixed-initialization-safety-1-error.cpp2 @@ -0,0 +1,45 @@ + +#include +#include +#include +#include +#include +#include + +fill: ( + out x: std::string, + in value: std::string, + in count: int + ) + pre( value.size() >= count, "fill: value must contain at least count elements" ) += { + x = value.substr(0, count); +} + +main: () -> int = +{ + x: std::string; // note: uninitialized! + + // if flip_a_coin() { + // x = "xyzzy"; + // } + // else { + // // fill( out x, "plugh", 40 ); // note: constructs x! + // } + + print_decorated(x); +} + +// Print! A one-expression function body... +// +print_decorated: (x:_) = std::cout << ">> [" << x << "]\n"; + +// Flip a coin! Exercise and 'as'... +// +rand_init_flag: std::once_flag = (); + +flip_a_coin: () -> bool = { + std::call_once(rand_init_flag, srand, time(nullptr) as unsigned ); + return std::rand()%2; +} + -- cgit v1.2.3