libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

char.bad.fail.cpp (1674B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <string_view>
     11 //   ... manipulating sequences of any non-array trivial standard-layout types.
     12 
     13 #include <string>
     14 #include "../basic.string/test_traits.h"
     15 
     16 struct NotTrivial {
     17     NotTrivial() : value(3) {}
     18     int value;
     19 };
     20 
     21 struct NotStandardLayout {
     22 public:
     23     NotStandardLayout() : one(1), two(2) {}
     24     int sum() const { return one + two; } // silences "unused field 'two' warning"
     25     int one;
     26 private:
     27     int two;
     28 };
     29 
     30 int main()
     31 {
     32     {
     33 //  array
     34     typedef char C[3];
     35     static_assert(std::is_array<C>::value, "");
     36     std::basic_string_view<C, test_traits<C> > sv;
     37 //  expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must not be an array"}}
     38     }
     39 
     40     {
     41 //  not trivial
     42     static_assert(!std::is_trivial<NotTrivial>::value, "");
     43     std::basic_string_view<NotTrivial, test_traits<NotTrivial> > sv;
     44 //  expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be trivial"}}
     45     }
     46 
     47     {
     48 //  not standard layout
     49     static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
     50     std::basic_string_view<NotStandardLayout, test_traits<NotStandardLayout> > sv;
     51 //  expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be standard-layout"}}
     52     }
     53 }