Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / pr83239.C
blob92af1b957c1194a87bd2773ad260b111b02dc417
1 // PR tree-optimization/83239 - False positive from -Wstringop-overflow
2 // on simple std::vector code
3 // { dg-do compile }
4 // { dg-options "-O3 -finline-limit=500 -Wall -fdump-tree-optimized"  }
5 // { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } }
7 #include <vector>
9 // Verify no warnings are issued.
11 template <class T>
12 void test_loop ()
14   std::vector<T> a;
16   int num = 2;
18   while (num > 0)
19     {
20       const typename std::vector<T>::size_type sz = a.size ();
22       if (sz < 3)
23         a.assign (1, 0);
24       else
25         a.resize (sz - 2);
27       --num;
28     }
31 // Verify no warnings are issued here either.
33 template <class T>
34 void test_if (std::vector<T> &a, int num)
36   if (num > 0)
37     {
38       const typename std::vector<T>::size_type sz = a.size ();
40       if (sz < 3)
41         a.assign (1, 0);
42       else
43         a.resize (sz - 2);
44     }
47 // Instantiate each function on a different type to force both
48 // to be fully inlined.  Instantiating both on the same type
49 // causes the inlining heuristics to outline _M_default_append
50 // which, in turn, masks the warning.
51 template void test_loop<int>();
52 template void test_if<long>(std::vector<long>&, int);
54 // Verify that std::vector<T>::_M_default_append() has been inlined
55 // (the absence of warnings depends on it).
56 // { dg-final { scan-tree-dump-not "_ZNSt6vectorIiSaIiEE17_M_default_appendEm"  optimized } }
57 // { dg-final { scan-tree-dump-not "_ZNSt6vectorIPvSaIS0_EE17_M_default_appendEm" optimized } }