brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.9 KiB · 0b9a88d Raw
129 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <span>11 12// template<class OtherElementType, size_t OtherExtent>13//    constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;14//15//  Remarks: This constructor shall not participate in overload resolution unless:16//      Extent == dynamic_extent || Extent == OtherExtent is true, and17//      OtherElementType(*)[] is convertible to ElementType(*)[].18 19#include <span>20#include <cassert>21#include <string>22 23#include "test_macros.h"24 25template <class T, std::size_t extent, size_t otherExtent>26std::span<T, extent> createImplicitSpan(std::span<T, otherExtent> s) {27  return {s}; // expected-error {{chosen constructor is explicit in copy-initialization}}28}29 30void checkCV() {31  //  std::span<               int>   sp;32  std::span<const int> csp;33  std::span< volatile int> vsp;34  std::span<const volatile int> cvsp;35 36  //  std::span<               int, 0>   sp0;37  std::span<const int, 0> csp0;38  std::span< volatile int, 0> vsp0;39  std::span<const volatile int, 0> cvsp0;40 41  //  Try to remove const and/or volatile (dynamic -> dynamic)42  {43    std::span< int> s1{csp};  // expected-error {{no matching constructor for initialization of 'std::span<int>'}}44    std::span< int> s2{vsp};  // expected-error {{no matching constructor for initialization of 'std::span<int>'}}45    std::span< int> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}46 47    std::span<const int> s4{vsp};48    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int>'}}49    std::span<const int> s5{cvsp};50    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int>'}}51 52    std::span< volatile int> s6{csp};53    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int>'}}54    std::span< volatile int> s7{cvsp};55    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int>'}}56  }57 58  //  Try to remove const and/or volatile (static -> static)59  {60    std::span< int, 0> s1{csp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}61    std::span< int, 0> s2{vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}62    std::span< int, 0> s3{cvsp0};63    // expected-error@-1 {{no matching constructor for initialization of 'std::span<int, 0>'}}64 65    std::span<const int, 0> s4{vsp0};66    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int, 0>'}}67    std::span<const int, 0> s5{cvsp0};68    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int, 0>'}}69 70    std::span< volatile int, 0> s6{csp0};71    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}72    std::span< volatile int, 0> s7{cvsp0};73    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}74  }75 76  //  Try to remove const and/or volatile (static -> dynamic)77  {78    std::span< int> s1{csp0};  // expected-error {{no matching constructor for initialization of 'std::span<int>'}}79    std::span< int> s2{vsp0};  // expected-error {{no matching constructor for initialization of 'std::span<int>'}}80    std::span< int> s3{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}81 82    std::span<const int> s4{vsp0};83    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int>'}}84    std::span<const int> s5{cvsp0};85    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int>'}}86 87    std::span< volatile int> s6{csp0};88    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int>'}}89    std::span< volatile int> s7{cvsp0};90    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int>'}}91  }92 93  //  Try to remove const and/or volatile (static -> static)94  {95    std::span< int, 0> s1{csp};  // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}96    std::span< int, 0> s2{vsp};  // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}97    std::span< int, 0> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}98 99    std::span<const int, 0> s4{vsp};100    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int, 0>'}}101    std::span<const int, 0> s5{cvsp};102    // expected-error@-1 {{no matching constructor for initialization of 'std::span<const int, 0>'}}103 104    std::span< volatile int, 0> s6{csp};105    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}106    std::span< volatile int, 0> s7{cvsp};107    // expected-error@-1 {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}108  }109}110 111int main(int, char**) {112  std::span<int> sp;113  std::span<int, 0> sp0;114 115  std::span<float> s1{sp};     // expected-error {{no matching constructor for initialization of 'std::span<float>'}}116  std::span<float> s2{sp0};    // expected-error {{no matching constructor for initialization of 'std::span<float>'}}117  std::span<float, 0> s3{sp};  // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}}118  std::span<float, 0> s4{sp0}; // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}}119 120  checkCV();121 122  // explicit constructor necessary123  {124    createImplicitSpan<int, 1>(sp);125  }126 127  return 0;128}129