-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress execution checks for
expected
- Loading branch information
Showing
4 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
libcudacxx/test/libcudacxx/cuda/utilities/expected/device_only_types.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the libcu++ Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <cuda/std/cassert> | ||
#include <cuda/std/expected> | ||
|
||
#include "test_macros.h" | ||
|
||
struct device_only_type | ||
{ | ||
int val_; | ||
|
||
__device__ device_only_type(const int val = 0) noexcept | ||
: val_(val) | ||
{} | ||
|
||
__device__ device_only_type(const device_only_type& other) noexcept | ||
: val_(other.val_) | ||
{} | ||
__device__ device_only_type(device_only_type&& other) noexcept | ||
: val_(cuda::std::exchange(other.val_, -1)) | ||
{} | ||
|
||
__device__ device_only_type& operator=(const device_only_type& other) noexcept | ||
{ | ||
val_ = other.val_; | ||
return *this; | ||
} | ||
|
||
__device__ device_only_type& operator=(device_only_type&& other) noexcept | ||
|
||
{ | ||
val_ = cuda::std::exchange(other.val_, -1); | ||
return *this; | ||
} | ||
|
||
__device__ ~device_only_type() noexcept {} | ||
|
||
__device__ bool operator==(const int other) noexcept | ||
{ | ||
return other == val_; | ||
} | ||
__device__ bool operator!=(const int other) noexcept | ||
{ | ||
return other != val_; | ||
} | ||
}; | ||
|
||
__device__ void test() | ||
{ | ||
using expected = cuda::std::expected<device_only_type, device_only_type>; | ||
{ // default construction | ||
expected default_constructed{}; | ||
assert(default_constructed.has_value()); | ||
assert(*default_constructed == 0); | ||
} | ||
|
||
{ // in_place zero initialization | ||
expected in_place_zero_initialization{cuda::std::in_place}; | ||
assert(in_place_zero_initialization.has_value()); | ||
assert(*in_place_zero_initialization == 0); | ||
} | ||
|
||
{ // in_place initialization | ||
expected in_place_initialization{cuda::std::in_place, 42}; | ||
assert(in_place_initialization.has_value()); | ||
assert(*in_place_initialization == 42); | ||
} | ||
|
||
{ // unexpect zero initialization | ||
expected in_place_zero_initialization{cuda::std::unexpect}; | ||
assert(!in_place_zero_initialization.has_value()); | ||
assert(in_place_zero_initialization.error() == 0); | ||
} | ||
|
||
{ // unexpect initialization | ||
expected in_place_initialization{cuda::std::unexpect, 42}; | ||
assert(!in_place_initialization.has_value()); | ||
assert(in_place_initialization.error() == 42); | ||
} | ||
|
||
{ // value initialization | ||
expected value_initialization{42}; | ||
assert(value_initialization.has_value()); | ||
assert(*value_initialization == 42); | ||
} | ||
|
||
{ // copy construction | ||
expected input{42}; | ||
expected dest{input}; | ||
assert(dest.has_value()); | ||
assert(*dest == 42); | ||
} | ||
|
||
{ // move construction | ||
expected input{42}; | ||
expected dest{cuda::std::move(input)}; | ||
assert(dest.has_value()); | ||
assert(*dest == 42); | ||
} | ||
|
||
{ // assignment, value to value | ||
expected input{42}; | ||
expected dest{1337}; | ||
dest = input; | ||
assert(dest.has_value()); | ||
assert(*dest == 42); | ||
} | ||
|
||
{ // assignment, value to empty | ||
expected input{42}; | ||
expected dest{}; | ||
dest = input; | ||
assert(dest.has_value()); | ||
assert(*dest == 42); | ||
} | ||
|
||
{ // assignment, empty to value | ||
expected input{}; | ||
expected dest{1337}; | ||
dest = input; | ||
assert(dest.has_value()); | ||
assert(*dest == 0); | ||
} | ||
|
||
{ // assignment, empty to empty | ||
expected input{}; | ||
expected dest{}; | ||
dest = input; | ||
assert(dest.has_value()); | ||
assert(*dest == 0); | ||
} | ||
|
||
{ // assignment, error to value | ||
expected input{cuda::std::unexpect, 42}; | ||
expected dest{1337}; | ||
dest = input; | ||
assert(!dest.has_value()); | ||
assert(dest.error() == 42); | ||
} | ||
|
||
{ // assignment, value to error | ||
expected input{42}; | ||
expected dest{cuda::std::unexpect, 1337}; | ||
dest = input; | ||
assert(dest.has_value()); | ||
assert(*dest == 42); | ||
} | ||
|
||
{ // assignment, error to error | ||
expected input{cuda::std::unexpect, 42}; | ||
expected dest{cuda::std::unexpect, 1337}; | ||
dest = input; | ||
assert(!dest.has_value()); | ||
assert(dest.error() == 42); | ||
} | ||
} | ||
|
||
int main(int arg, char** argv) | ||
{ | ||
NV_IF_TARGET(NV_IS_DEVICE, (test();)) | ||
return 0; | ||
} |
Oops, something went wrong.