annotate clang/test/SemaCXX/warn-range-loop-analysis-trivially-copyable.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 0572611fdcc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -verify %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wrange-loop-analysis -verify %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 void test_POD_64_bytes() {
anatofuz
parents:
diff changeset
5 struct Record {
anatofuz
parents:
diff changeset
6 char a[64];
anatofuz
parents:
diff changeset
7 };
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 Record records[8];
anatofuz
parents:
diff changeset
10 for (const auto r : records)
anatofuz
parents:
diff changeset
11 (void)r;
anatofuz
parents:
diff changeset
12 }
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 void test_POD_65_bytes() {
anatofuz
parents:
diff changeset
15 struct Record {
anatofuz
parents:
diff changeset
16 char a[65];
anatofuz
parents:
diff changeset
17 };
anatofuz
parents:
diff changeset
18
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
19 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
150
anatofuz
parents:
diff changeset
20 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
anatofuz
parents:
diff changeset
21 Record records[8];
anatofuz
parents:
diff changeset
22 for (const auto r : records)
anatofuz
parents:
diff changeset
23 (void)r;
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 void test_TriviallyCopyable_64_bytes() {
anatofuz
parents:
diff changeset
27 struct Record {
anatofuz
parents:
diff changeset
28 Record() {}
anatofuz
parents:
diff changeset
29 char a[64];
anatofuz
parents:
diff changeset
30 };
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 Record records[8];
anatofuz
parents:
diff changeset
33 for (const auto r : records)
anatofuz
parents:
diff changeset
34 (void)r;
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 void test_TriviallyCopyable_65_bytes() {
anatofuz
parents:
diff changeset
38 struct Record {
anatofuz
parents:
diff changeset
39 Record() {}
anatofuz
parents:
diff changeset
40 char a[65];
anatofuz
parents:
diff changeset
41 };
anatofuz
parents:
diff changeset
42
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
43 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
150
anatofuz
parents:
diff changeset
44 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
anatofuz
parents:
diff changeset
45 Record records[8];
anatofuz
parents:
diff changeset
46 for (const auto r : records)
anatofuz
parents:
diff changeset
47 (void)r;
anatofuz
parents:
diff changeset
48 }
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 void test_NonTriviallyCopyable() {
anatofuz
parents:
diff changeset
51 struct Record {
anatofuz
parents:
diff changeset
52 Record() {}
anatofuz
parents:
diff changeset
53 ~Record() {}
anatofuz
parents:
diff changeset
54 volatile int a;
anatofuz
parents:
diff changeset
55 int b;
anatofuz
parents:
diff changeset
56 };
anatofuz
parents:
diff changeset
57
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
58 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
150
anatofuz
parents:
diff changeset
59 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
anatofuz
parents:
diff changeset
60 Record records[8];
anatofuz
parents:
diff changeset
61 for (const auto r : records)
anatofuz
parents:
diff changeset
62 (void)r;
anatofuz
parents:
diff changeset
63 }
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 void test_TrivialABI_64_bytes() {
anatofuz
parents:
diff changeset
66 struct [[clang::trivial_abi]] Record {
anatofuz
parents:
diff changeset
67 Record() {}
anatofuz
parents:
diff changeset
68 ~Record() {}
anatofuz
parents:
diff changeset
69 char a[64];
anatofuz
parents:
diff changeset
70 };
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 Record records[8];
anatofuz
parents:
diff changeset
73 for (const auto r : records)
anatofuz
parents:
diff changeset
74 (void)r;
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 void test_TrivialABI_65_bytes() {
anatofuz
parents:
diff changeset
78 struct [[clang::trivial_abi]] Record {
anatofuz
parents:
diff changeset
79 Record() {}
anatofuz
parents:
diff changeset
80 ~Record() {}
anatofuz
parents:
diff changeset
81 char a[65];
anatofuz
parents:
diff changeset
82 };
anatofuz
parents:
diff changeset
83
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
84 // expected-warning@+3 {{loop variable 'r' creates a copy from type 'const Record'}}
150
anatofuz
parents:
diff changeset
85 // expected-note@+2 {{use reference type 'const Record &' to prevent copying}}
anatofuz
parents:
diff changeset
86 Record records[8];
anatofuz
parents:
diff changeset
87 for (const auto r : records)
anatofuz
parents:
diff changeset
88 (void)r;
anatofuz
parents:
diff changeset
89 }