diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2023-12-30 23:39:37 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2023-12-30 23:39:37 +0100 |
| commit | 263915832993dd12beee10e204f9ebcc6c786ed2 (patch) | |
| tree | 862e51208a99c35746e574a76564a4532b3a4a49 /CompilerDriver/cc2/regression-tests/mixed-initialization-safety-2-error.cpp2 | |
Meta: initial commit of WestCo optimized toolchain.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver/cc2/regression-tests/mixed-initialization-safety-2-error.cpp2')
| -rw-r--r-- | CompilerDriver/cc2/regression-tests/mixed-initialization-safety-2-error.cpp2 | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/CompilerDriver/cc2/regression-tests/mixed-initialization-safety-2-error.cpp2 b/CompilerDriver/cc2/regression-tests/mixed-initialization-safety-2-error.cpp2 new file mode 100644 index 0000000..39da2f3 --- /dev/null +++ b/CompilerDriver/cc2/regression-tests/mixed-initialization-safety-2-error.cpp2 @@ -0,0 +1,45 @@ + +#include <string> +#include <vector> +#include <mutex> +#include <cstdlib> +#include <ctime> +#include <cstdio> + +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 <mutex> <cstdlib> <ctime> 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; +} + |
