1// Copyright (C) 2003-2015 Free Software Foundation, Inc. 2// 3// This file is part of the GNU ISO C++ Library. This library is free 4// software; you can redistribute it and/or modify it under the 5// terms of the GNU General Public License as published by the 6// Free Software Foundation; either version 3, or (at your option) 7// any later version. 8 9// This library is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13 14// You should have received a copy of the GNU General Public License along 15// with this library; see the file COPYING3. If not see 16// <http://www.gnu.org/licenses/>. 17 18// { dg-require-time "" } 19 20// 22.2.5.3.1 time_put members 21 22#include <locale> 23#include <sstream> 24#include <ctime> 25#include <cstring> 26#include <testsuite_hooks.h> 27 28// libstdc++/12439 29// time_put::put writes narrowed characters to output iterator 30void test02() 31{ 32 using namespace std; 33 bool test __attribute__((unused)) = true; 34 35 typedef time_put<wchar_t> tp_type; 36 37 const wchar_t fmt[] = { 38 0xa0, 0x103, 0xfc, 0xb3, 0xa0c3, 39 L'%', L'c' 40 }; 41 42 const size_t len = sizeof(fmt) / sizeof(fmt[0]); 43 const size_t cmplen = wcschr(fmt, L'%') - fmt; 44 45 locale loc; 46 const tp_type& tp = use_facet<tp_type>(loc); 47 time_t tt = time(0); 48 wostringstream stream; 49 50 tp.put(tp_type::iter_type(stream), stream, stream.fill(), 51 localtime(&tt), fmt, fmt + len); 52 wstring str = stream.str(); 53 VERIFY( str.length() >= cmplen ); 54 VERIFY( !wmemcmp(str.data(), fmt, cmplen) ); 55} 56 57int main() 58{ 59 test02(); 60 return 0; 61} 62