150
|
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -verify %s
|
|
2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wrange-loop-analysis -verify %s
|
|
3
|
|
4 void test_POD_64_bytes() {
|
|
5 struct Record {
|
|
6 char a[64];
|
|
7 };
|
|
8
|
|
9 Record records[8];
|
|
10 for (const auto r : records)
|
|
11 (void)r;
|
|
12 }
|
|
13
|
|
14 void test_POD_65_bytes() {
|
|
15 struct Record {
|
|
16 char a[65];
|
|
17 };
|
|
18
|
173
|
19 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
|
150
|
20 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
|
|
21 Record records[8];
|
|
22 for (const auto r : records)
|
|
23 (void)r;
|
|
24 }
|
|
25
|
|
26 void test_TriviallyCopyable_64_bytes() {
|
|
27 struct Record {
|
|
28 Record() {}
|
|
29 char a[64];
|
|
30 };
|
|
31
|
|
32 Record records[8];
|
|
33 for (const auto r : records)
|
|
34 (void)r;
|
|
35 }
|
|
36
|
|
37 void test_TriviallyCopyable_65_bytes() {
|
|
38 struct Record {
|
|
39 Record() {}
|
|
40 char a[65];
|
|
41 };
|
|
42
|
173
|
43 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
|
150
|
44 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
|
|
45 Record records[8];
|
|
46 for (const auto r : records)
|
|
47 (void)r;
|
|
48 }
|
|
49
|
|
50 void test_NonTriviallyCopyable() {
|
|
51 struct Record {
|
|
52 Record() {}
|
|
53 ~Record() {}
|
|
54 volatile int a;
|
|
55 int b;
|
|
56 };
|
|
57
|
173
|
58 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
|
150
|
59 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
|
|
60 Record records[8];
|
|
61 for (const auto r : records)
|
|
62 (void)r;
|
|
63 }
|
|
64
|
|
65 void test_TrivialABI_64_bytes() {
|
|
66 struct [[clang::trivial_abi]] Record {
|
|
67 Record() {}
|
|
68 ~Record() {}
|
|
69 char a[64];
|
|
70 };
|
|
71
|
|
72 Record records[8];
|
|
73 for (const auto r : records)
|
|
74 (void)r;
|
|
75 }
|
|
76
|
|
77 void test_TrivialABI_65_bytes() {
|
|
78 struct [[clang::trivial_abi]] Record {
|
|
79 Record() {}
|
|
80 ~Record() {}
|
|
81 char a[65];
|
|
82 };
|
|
83
|
173
|
84 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
|
150
|
85 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
|
|
86 Record records[8];
|
|
87 for (const auto r : records)
|
|
88 (void)r;
|
|
89 }
|