Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / copypaste / call.cpp
blobc5ddae5a65f3e0f5e74ebbf0061379848ad5d423
1 // RUN: %clang_analyze_cc1 -std=c++1z -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
3 // expected-no-diagnostics
5 bool a();
6 bool b();
8 // Calls method a with some extra code to pass the minimum complexity
9 bool foo1(int x) {
10 if (x > 0)
11 return false;
12 else if (x < 0)
13 return a();
14 return true;
17 // Calls method b with some extra code to pass the minimum complexity
18 bool foo2(int x) {
19 if (x > 0)
20 return false;
21 else if (x < 0)
22 return b();
23 return true;
26 // Test that we don't crash on function pointer calls
28 bool (*funcPtr)(int);
30 bool fooPtr1(int x) {
31 if (x > 0)
32 return false;
33 else if (x < 0)
34 return funcPtr(1);
35 return true;
38 // Test that we respect the template arguments of function templates
40 template<typename T, unsigned N>
41 bool templateFunc() { unsigned i = N; return false; }
43 bool fooTemplate1(int x) {
44 if (x > 0)
45 return false;
46 else if (x < 0)
47 return templateFunc<int, 1>();
48 return true;
51 bool fooTemplate2(int x) {
52 if (x > 0)
53 return false;
54 else if (x < 0)
55 return templateFunc<long, 1>();
56 return true;
59 bool fooTemplate3(int x) {
60 if (x > 0)
61 return false;
62 else if (x < 0)
63 return templateFunc<long, 2>();
64 return true;
67 // Test that we don't just concatenate the template arguments into a string
68 // without having any padding between them (e.g. foo<X, XX>() != foo<XX, X>()).
70 class X {};
71 class XX {};
73 template<typename T1, typename T2>
74 bool templatePaddingFunc() { return false; }
76 bool fooTemplatePadding1(int x) {
77 if (x > 0)
78 return false;
79 else if (x < 0)
80 return templatePaddingFunc<X, XX>();
81 return true;
84 bool fooTemplatePadding2(int x) {
85 if (x > 0)
86 return false;
87 else if (x < 0)
88 return templatePaddingFunc<XX, X>();
89 return true;
92 // Test that we don't crash on member functions of template instantiations.
94 template<typename T>
95 struct A {
96 void foo(T t) {}
99 void fooTestInstantiation() {
100 A<int> a;
101 a.foo(1);