84 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -fblocks -verify -analyzer-config eagerly-assume=false %s2// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -fblocks -analyzer-config c++-template-inlining=false -DNO_INLINE -verify -analyzer-config eagerly-assume=false %s3 4void clang_analyzer_eval(bool);5 6// Do not crash on this templated code which uses a block.7typedef void (^my_block)(void);8static void useBlock(my_block block){}9template<class T> class MyClass;10typedef MyClass<float> Mf;11 12template<class T>13class MyClass14{15public:16 MyClass() {}17 MyClass(T a);18 void I();19private:20 static const T one;21};22 23template<class T> const T MyClass<T>::one = static_cast<T>(1);24template<class T> inline MyClass<T>::MyClass(T a){}25template<class T> void MyClass<T>::I() {26 static MyClass<T>* mPtr = 0;27 useBlock(^{ mPtr = new MyClass<T> (MyClass<T>::one); });28};29int main(){30 Mf m;31 m.I();32}33 34template<class T, unsigned N>35inline unsigned array_lengthof(T (&)[N]) {36 return N;37}38 39void testNonTypeTemplateInstantiation() {40 const char *S[] = { "a", "b" };41 clang_analyzer_eval(array_lengthof(S) == 2);42#ifndef NO_INLINE43 // expected-warning@-2 {{TRUE}}44#else45 // expected-warning@-4 {{UNKNOWN}}46#endif47}48 49namespace rdar13954714 {50 template <bool VALUE>51 bool blockInTemplate() {52 return (^() {53 return VALUE;54 })();55 }56 57 // force instantiation58 template bool blockInTemplate<true>();59 60 template <bool VALUE>61 void blockWithStatic() {62 (void)^() {63 static int x;64 return ++x;65 };66 }67 68 // force instantiation69 template void blockWithStatic<true>();70}71 72namespace structural_value_crash {73 constexpr char abc[] = "abc";74 75 template <const char* in>76 void use_template_param() {77 const char *p = in;78 }79 80 void force_instantiate() {81 use_template_param<abc>();82 }83}84