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