File: 8.cc

package info (click to toggle)
gcc-arm-none-eabi 15%3A8-2019-q3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 571,828 kB
  • sloc: ansic: 2,937,651; cpp: 881,644; ada: 597,189; makefile: 65,528; asm: 56,499; xml: 46,621; exp: 24,747; sh: 19,684; python: 7,256; pascal: 4,370; awk: 3,497; perl: 2,695; yacc: 316; ml: 285; f90: 234; lex: 198; objc: 194; haskell: 119
file content (83 lines) | stat: -rw-r--r-- 2,681 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (C) 2016-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-options "-O0" }
// { dg-do run { target c++11 } }

#include <string>
#include <testsuite_hooks.h>

struct TestBaseObjCtor : std::wstring
{
  template<typename... Args>
    TestBaseObjCtor(Args&&... args)
    : std::wstring(std::forward<Args>(args)...)
    { }
};

template<typename... Args>
std::size_t
construct(Args&&... args)
{
  // Use static_cast<Args> to produce either an lvalue or prvalue,
  // so args... not left in moved-from state and can be reused below:
  TestBaseObjCtor as_base_obj( static_cast<Args>(args)... );

  std::wstring as_complete_obj( std::forward<Args>(args)... );

  return as_complete_obj.length();
}

void
test01()
{
  using string = std::wstring;
  using list = std::initializer_list<string::value_type>;

  const std::wstring lvalue = L"lvalue";
  std::allocator<char> alloc;

  // test all valid combinations of arguments:
  VERIFY( construct( ) == 0 );
  VERIFY( construct( alloc ) == 0 );
  VERIFY( construct( lvalue ) == 6 );
  VERIFY( construct( string{L"rvalue"} ) == 6 );
  VERIFY( construct( lvalue, 2 ) == 4 );
  VERIFY( construct( lvalue, 2, alloc ) == 4 );
  VERIFY( construct( lvalue, 2, 3 ) == 3 );
  VERIFY( construct( lvalue, 2, 3, alloc ) == 3 );
  VERIFY( construct( L"C string", 4 ) == 4 );
  VERIFY( construct( L"C string", 4, alloc ) == 4 );
  VERIFY( construct( L"C string" ) == 8 );
  VERIFY( construct( L"C string and alloc", alloc ) == 18 );
  VERIFY( construct( 5, L' ' ) == 5 );
  VERIFY( construct( 5, L' ', alloc ) == 5 );
  VERIFY( construct( lvalue.begin(), lvalue.end() ) == 6 );
  VERIFY( construct( lvalue.begin(), lvalue.end(), alloc ) == 6 );
  VERIFY( construct( list{ L'l' , L'i' , L's', L't' } ) == 4 );
  VERIFY( construct( list{ L'l', L'i', L's', L't' }, alloc ) == 4 );
#if _GLIBCXX_USE_CXX11_ABI
  VERIFY( construct( lvalue, alloc ) == 6 );
  VERIFY( construct( string{L"rvalue"}, alloc ) == 6 );
#endif
}

int
main()
{
  test01();
}