blob: b0f31be33f1f0413cdd503f14836e3cf6a988fe8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// PR tree-optimization/83239 - False positive from -Wstringop-overflow
// on simple std::vector code
// { dg-do compile }
// { dg-options "-O3 -Wall -fdump-tree-optimized" }
#include <vector>
// Verify no warnings are issued.
template <class T>
void test_loop ()
{
std::vector<T> a;
int num = 2;
while (num > 0)
{
const typename std::vector<T>::size_type sz = a.size ();
if (sz < 3)
a.assign (1, 0);
else
a.resize (sz - 2);
--num;
}
}
// Verify no warnings are issued here either.
template <class T>
void test_if (std::vector<T> &a, int num)
{
if (num > 0)
{
const typename std::vector<T>::size_type sz = a.size ();
if (sz < 3)
a.assign (1, 0);
else
a.resize (sz - 2);
}
}
// Instantiate each function on a different type to force both
// to be fully inlined. Instantiating both on the same type
// causes the inlining heuristics to outline _M_default_append
// which, in turn, masks the warning.
template void test_loop<int>();
template void test_if<long>(std::vector<long>&, int);
// Verify that std::vector<T>::_M_default_append() has been inlined
// (the absence of warnings depends on it).
// { dg-final { scan-tree-dump-not "_ZNSt6vectorIiSaIiEE17_M_default_appendEm" optimized } }
// { dg-final { scan-tree-dump-not "_ZNSt6vectorIPvSaIS0_EE17_M_default_appendEm" optimized } }
|