Clang Project

clang_source_code/test/Analysis/copypaste/sub-sequences.cpp
1// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
2
3// This tests if sub-sequences can match with normal sequences.
4
5void log2(int a);
6void log();
7
8int max(int a, int b) {
9  log2(a);
10  log(); // expected-warning{{Duplicate code detected}}
11  if (a > b)
12    return a;
13  return b;
14}
15
16int maxClone(int a, int b) {
17  log(); // expected-note{{Similar code here}}
18  if (a > b)
19    return a;
20  return b;
21}
22
23// Functions below are not clones and should not be reported.
24
25int foo(int a, int b) { // no-warning
26  return a + b;
27}
28