1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -std=c++11 -verify %s 2 3 // PR12871 4 class PlotPoint { 5 bool valid; 6 }; 7 limitedFit()8PlotPoint limitedFit () { 9 PlotPoint fit0; 10 fit0 = limitedFit (); 11 return fit0; 12 } 13 14 namespace boost {namespace filesystem3 { 15 class path { 16 public: path()17 path(){} 18 }; 19 20 }} 21 namespace boost 22 { 23 namespace filesystem 24 { 25 using filesystem3::path; 26 } 27 } 28 radar11487541()29void radar11487541() { 30 namespace fs = boost::filesystem; 31 fs::path p; 32 } 33 34 // PR12873 testFloatInitializer()35void testFloatInitializer() { 36 const float ysize={0.015}, xsize={0.01}; 37 } 38 39 40 // PR12874 41 template<class T> struct addr_impl_ref { 42 T & v_; addr_impl_refaddr_impl_ref43 inline addr_impl_ref( T & v ): v_( v ) { 44 } operator T&addr_impl_ref45 inline operator T& () const {return v_;} 46 }; 47 template<class T> struct addressof_impl { faddressof_impl48 static inline T * f( T & v, long ) { 49 return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char &>(v))); 50 } 51 }; addressof(T & v)52template<class T> T * addressof( T & v ) { 53 return addressof_impl<T>::f( addr_impl_ref<T>( v ), 0 ); 54 } testRadar11487525_1()55void testRadar11487525_1(){ 56 bool s[25]; 57 addressof(s); 58 } 59 60 // Don't crash on CK_LValueBitCast. begin(double * it)61bool begin(double *it) { 62 typedef bool type[25]; 63 bool *a = reinterpret_cast<type &>(*( reinterpret_cast<char *>( it ))); 64 return *a; 65 } 66 67 // Don't crash on "assuming" a ComoundVal. 68 class JSONWireProtocolInputStream { 69 public: 70 virtual ~JSONWireProtocolInputStream(); 71 }; 72 class JSONWireProtocolReader { 73 public: JSONWireProtocolReader(JSONWireProtocolInputStream & istream)74 JSONWireProtocolReader(JSONWireProtocolInputStream& istream) 75 : _istream{istream} {} // On evaluating a bind here, 76 // the dereference checker issues an assume on a CompoundVal. 77 ~JSONWireProtocolReader(); 78 private: 79 JSONWireProtocolInputStream& _istream; 80 }; 81 class SocketWireProtocolStream : public JSONWireProtocolInputStream { 82 }; test()83void test() { 84 SocketWireProtocolStream stream{}; 85 JSONWireProtocolReader reader{stream}; 86 } 87 88 // This crashed because the analyzer did not understand AttributedStmts. fallthrough()89void fallthrough() { 90 switch (1) { 91 case 1: 92 [[clang::fallthrough]]; // expected-error {{does not directly precede}} 93 } 94 } 95