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// <istream> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_istream; 14 15// operator>>(void*& val); 16 17#include <istream> 18#include <cassert> 19 20template <class CharT> 21struct testbuf 22 : public std::basic_streambuf<CharT> 23{ 24 typedef std::basic_string<CharT> string_type; 25 typedef std::basic_streambuf<CharT> base; 26private: 27 string_type str_; 28public: 29 30 testbuf() {} 31 testbuf(const string_type& str) 32 : str_(str) 33 { 34 base::setg(const_cast<CharT*>(str_.data()), 35 const_cast<CharT*>(str_.data()), 36 const_cast<CharT*>(str_.data()) + str_.size()); 37 } 38 39 CharT* eback() const {return base::eback();} 40 CharT* gptr() const {return base::gptr();} 41 CharT* egptr() const {return base::egptr();} 42}; 43 44int main() 45{ 46 { 47 std::istream is((std::streambuf*)0); 48 void* n = 0; 49 is >> n; 50 assert(is.fail()); 51 } 52 { 53 testbuf<char> sb("0"); 54 std::istream is(&sb); 55 void* n = (void*)1; 56 is >> n; 57 assert(n == 0); 58 assert( is.eof()); 59 assert(!is.fail()); 60 } 61 { 62 testbuf<char> sb(" 1 "); 63 std::istream is(&sb); 64 void* n = 0; 65 is >> n; 66 assert(n == (void*)1); 67 assert(!is.eof()); 68 assert(!is.fail()); 69 } 70 { 71 testbuf<wchar_t> sb(L" 1 "); 72 std::wistream is(&sb); 73 void* n = 0; 74 is >> n; 75 assert(n == (void*)1); 76 assert(!is.eof()); 77 assert(!is.fail()); 78 } 79 { 80 testbuf<char> sb("12345678"); 81 std::istream is(&sb); 82 void* n = 0; 83 is >> n; 84 assert(n == (void*)0x12345678); 85 assert( is.eof()); 86 assert(!is.fail()); 87 } 88 { 89 testbuf<wchar_t> sb(L"12345678"); 90 std::wistream is(&sb); 91 void* n = 0; 92 is >> n; 93 assert(n == (void*)0x12345678); 94 assert( is.eof()); 95 assert(!is.fail()); 96 } 97} 98