blob: 671aa7858204190985e7abd71ac4f30890c31d37 [file] [log] [blame]
Jordan Rose69a0e502012-07-27 01:15:02 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -fblocks -verify %s
2
3void clang_analyzer_eval(bool);
Anna Zaks45246a72012-05-14 22:38:24 +00004
5// Do not crash on this templated code which uses a block.
6typedef void (^my_block)(void);
7static void useBlock(my_block block){}
8template<class T> class MyClass;
9typedef MyClass<float> Mf;
10
11template<class T>
12class MyClass
13{
14public:
15 MyClass() {}
16 MyClass(T a);
17 void I();
18private:
19 static const T one;
20};
21
22template<class T> const T MyClass<T>::one = static_cast<T>(1);
23template<class T> inline MyClass<T>::MyClass(T a){}
24template<class T> void MyClass<T>::I() {
25 static MyClass<T>* mPtr = 0;
26 useBlock(^{ mPtr = new MyClass<T> (MyClass<T>::one); });
27};
28int main(){
29 Mf m;
30 m.I();
31}
Jordan Rose69a0e502012-07-27 01:15:02 +000032
33
34// <rdar://problem/11949235>
35template<class T, unsigned N>
36inline unsigned array_lengthof(T (&)[N]) {
37 return N;
38}
39
40void testNonTypeTemplateInstantiation() {
41 const char *S[] = { "a", "b" };
42 clang_analyzer_eval(array_lengthof(S) == 2); // expected-warning{{TRUE}}
43}
44