diff options
Diffstat (limited to 'test/Analysis/templates.cpp')
-rw-r--r-- | test/Analysis/templates.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/Analysis/templates.cpp b/test/Analysis/templates.cpp new file mode 100644 index 0000000..671aa78 --- /dev/null +++ b/test/Analysis/templates.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -fblocks -verify %s + +void clang_analyzer_eval(bool); + +// Do not crash on this templated code which uses a block. +typedef void (^my_block)(void); +static void useBlock(my_block block){} +template<class T> class MyClass; +typedef MyClass<float> Mf; + +template<class T> +class MyClass +{ +public: + MyClass() {} + MyClass(T a); + void I(); +private: + static const T one; +}; + +template<class T> const T MyClass<T>::one = static_cast<T>(1); +template<class T> inline MyClass<T>::MyClass(T a){} +template<class T> void MyClass<T>::I() { + static MyClass<T>* mPtr = 0; + useBlock(^{ mPtr = new MyClass<T> (MyClass<T>::one); }); +}; +int main(){ + Mf m; + m.I(); +} + + +// <rdar://problem/11949235> +template<class T, unsigned N> +inline unsigned array_lengthof(T (&)[N]) { + return N; +} + +void testNonTypeTemplateInstantiation() { + const char *S[] = { "a", "b" }; + clang_analyzer_eval(array_lengthof(S) == 2); // expected-warning{{TRUE}} +} + |