-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We did not properly implement the short circuiting for the `__span_compatible_range` concept. So the compiler tried to instantiate `iterator_t` even for non-ranges, which obviously failed. Fix this by properly implementing short circuiting.
- Loading branch information
Showing
2 changed files
with
60 additions
and
6 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
47 changes: 47 additions & 0 deletions
47
libcudacxx/test/libcudacxx/std/containers/views/views.span/span.cons/conversion.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,47 @@ | ||
//===---------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM 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) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// | ||
//===---------------------------------------------------------------------===// | ||
// UNSUPPORTED: c++03, c++11 | ||
|
||
// <cuda/std/span> | ||
|
||
// Conversion from a type that is *not* a range. We had a bug where we would still try to instantiate `iterator_t`, | ||
// which would fail because of a missing `begin` | ||
|
||
#include <cuda/std/cassert> | ||
#include <cuda/std/span> | ||
|
||
#include "test_macros.h" | ||
|
||
struct ConvertibleButNoRange | ||
{ | ||
int buffer[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
|
||
__host__ __device__ constexpr operator cuda::std::span<int>() const noexcept | ||
{ | ||
return cuda::std::span<int>{const_cast<int*>(buffer), 10}; | ||
} | ||
}; | ||
|
||
__host__ __device__ constexpr bool test() | ||
{ | ||
ConvertibleButNoRange input{}; | ||
cuda::std::span<int> converted = input; | ||
assert(converted.data() == input.buffer); | ||
assert(converted.size() == 10); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) | ||
{ | ||
test(); | ||
static_assert(test(), ""); | ||
|
||
return 0; | ||
} |