libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

pointer.pass.cpp (2444B)


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