char.bad.fail.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <string_view>
  9. // ... manipulating sequences of any non-array trivial standard-layout types.
  10. #include <string>
  11. #include "../basic.string/test_traits.h"
  12. struct NotTrivial {
  13. NotTrivial() : value(3) {}
  14. int value;
  15. };
  16. struct NotStandardLayout {
  17. public:
  18. NotStandardLayout() : one(1), two(2) {}
  19. int sum() const { return one + two; } // silences "unused field 'two' warning"
  20. int one;
  21. private:
  22. int two;
  23. };
  24. int main(int, char**)
  25. {
  26. {
  27. // array
  28. typedef char C[3];
  29. static_assert(std::is_array<C>::value, "");
  30. std::basic_string_view<C, test_traits<C> > sv;
  31. // expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must not be an array"}}
  32. }
  33. {
  34. // not trivial
  35. static_assert(!std::is_trivial<NotTrivial>::value, "");
  36. std::basic_string_view<NotTrivial, test_traits<NotTrivial> > sv;
  37. // expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be trivial"}}
  38. }
  39. {
  40. // not standard layout
  41. static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
  42. std::basic_string_view<NotStandardLayout, test_traits<NotStandardLayout> > sv;
  43. // expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be standard-layout"}}
  44. }
  45. return 0;
  46. }