[LLVM][IR] Use splat syntax when printing ConstantExpr based splats. (#116856)
[llvm-project.git] / clang / test / Analysis / templates.cpp
blob6da1821b70f26fa7def70f938c809c17e521148e
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -fblocks -verify -analyzer-config eagerly-assume=false %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -fblocks -analyzer-config c++-template-inlining=false -DNO_INLINE -verify -analyzer-config eagerly-assume=false %s
4 void clang_analyzer_eval(bool);
6 // Do not crash on this templated code which uses a block.
7 typedef void (^my_block)(void);
8 static void useBlock(my_block block){}
9 template<class T> class MyClass;
10 typedef MyClass<float> Mf;
12 template<class T>
13 class MyClass
15 public:
16 MyClass() {}
17 MyClass(T a);
18 void I();
19 private:
20 static const T one;
23 template<class T> const T MyClass<T>::one = static_cast<T>(1);
24 template<class T> inline MyClass<T>::MyClass(T a){}
25 template<class T> void MyClass<T>::I() {
26 static MyClass<T>* mPtr = 0;
27 useBlock(^{ mPtr = new MyClass<T> (MyClass<T>::one); });
29 int main(){
30 Mf m;
31 m.I();
34 template<class T, unsigned N>
35 inline unsigned array_lengthof(T (&)[N]) {
36 return N;
39 void testNonTypeTemplateInstantiation() {
40 const char *S[] = { "a", "b" };
41 clang_analyzer_eval(array_lengthof(S) == 2);
42 #ifndef NO_INLINE
43 // expected-warning@-2 {{TRUE}}
44 #else
45 // expected-warning@-4 {{UNKNOWN}}
46 #endif
49 namespace rdar13954714 {
50 template <bool VALUE>
51 bool blockInTemplate() {
52 return (^() {
53 return VALUE;
54 })();
57 // force instantiation
58 template bool blockInTemplate<true>();
60 template <bool VALUE>
61 void blockWithStatic() {
62 (void)^() {
63 static int x;
64 return ++x;
68 // force instantiation
69 template void blockWithStatic<true>();
72 namespace structural_value_crash {
73 constexpr char abc[] = "abc";
75 template <const char* in>
76 void use_template_param() {
77 const char *p = in;
80 void force_instantiate() {
81 use_template_param<abc>();