PR c++/86728 - C variadic generic lambda.
[official-gcc.git] / gcc / testsuite / g++.dg / pr83239.C
blobbf6be7a03cce87f1429d2759a39dfadcd3419ec9
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"  }
6 #include <vector>
8 // Verify no warnings are issued.
10 template <class T>
11 void test_loop ()
13   std::vector<T> a;
15   int num = 2;
17   while (num > 0)
18     {
19       const typename std::vector<T>::size_type sz = a.size ();
21       if (sz < 3)
22         a.assign (1, 0);
23       else
24         a.resize (sz - 2);
26       --num;
27     }
30 // Verify no warnings are issued here either.
32 template <class T>
33 void test_if (std::vector<T> &a, int num)
35   if (num > 0)
36     {
37       const typename std::vector<T>::size_type sz = a.size ();
39       if (sz < 3)
40         a.assign (1, 0);
41       else
42         a.resize (sz - 2);
43     }
46 // Instantiate each function on a different type to force both
47 // to be fully inlined.  Instantiating both on the same type
48 // causes the inlining heuristics to outline _M_default_append
49 // which, in turn, masks the warning.
50 template void test_loop<int>();
51 template void test_if<long>(std::vector<long>&, int);
53 // Verify that std::vector<T>::_M_default_append() has been inlined
54 // (the absence of warnings depends on it).
55 // { dg-final { scan-tree-dump-not "_ZNSt6vectorIiSaIiEE17_M_default_appendEm"  optimized } }
56 // { dg-final { scan-tree-dump-not "_ZNSt6vectorIPvSaIS0_EE17_M_default_appendEm" optimized } }