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