summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/22_locale/ctype/is/char/9858.cc
blob: d8b516263a4986dec12651de88d27e963ed38cb2 (plain)
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
84
85
86
87
88
89
90
91
92
93
// Copyright (C) 2003-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/>.


// 22.2.1.3 - ctype specializations [lib.facet.ctype.special]

#include <locale>
#include <testsuite_hooks.h>

int called;

class Derived : public std::ctype<char>
{
public:
  bool 
  do_is(mask, char_type) const { return true; }

  const char_type* 
  do_is(const char_type*, const char_type* hi, mask*) const 
  { return hi; }

  const char_type* 
  do_scan_is(mask, const char_type*, const char_type* hi) const 
  { return hi; }

  const char_type* 
  do_scan_not(mask, const char_type*, const char_type* hi) const 
  { return hi; }
};

class Derived2 : public Derived
{
public:
  bool 
  do_is(mask, char_type) const { called = 1; return true; }

  const char_type* 
  do_is(const char_type*, const char_type* hi, mask*) const 
  { called = 5; return hi; }

  const char_type* 
  do_scan_is(mask, const char_type*, const char_type* hi) const 
  { called = 10; return hi; }

  const char_type* 
  do_scan_not(mask, const char_type*, const char_type* hi) const 
  { called = 15; return hi; }
};

int main()
{
  using namespace std;
  Derived2 d2;
  const Derived& dr = d2;

  const char* lit = "jaylib champion sound";
  ctype_base::mask m00 = static_cast<std::ctype_base::mask>(0);
  ctype_base::mask vec[5];
  for (std::size_t i = 0; i < 5; ++i)
    vec[i] = m00;
 
  called = 0;
  dr.do_is(ctype_base::space, 'a');
  VERIFY( called !=  1);

  called = 0;
  dr.do_is(lit, lit + 5, vec);
  VERIFY( called !=  5);

  called = 0;
  dr.do_scan_is(ctype_base::space, lit, lit + 5);
  VERIFY( called !=  10);

  called = 0;
  dr.do_scan_not(ctype_base::space, lit, lit + 5);
  VERIFY( called !=  15);
  
  return 0;
}