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