PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / wrappers / pr83814.C
blobb9f8faad92ff749f4049b431a1d26d6f12bc9cc0
1 /* Verify that our memset warnings don't crash when folding
2    arguments within a template (PR c++/83814).  */
4 // { dg-options "-Wno-int-to-pointer-cast -Wmemset-transposed-args -Wmemset-elt-size" }
6 template <class>
7 void test_1()
9   __builtin_memset (int() - char(), 0, 0);
12 template <class>
13 void test_2()
15   __builtin_memset (0, 0, int() - char());
18 template <class>
19 void test_3 (unsigned a, int c)
21   __builtin_memset((char *)c + a, 0, a);
24 template <class>
25 void test_4 (unsigned a, int c)
27   __builtin_memset(0, 0, (char *)c + a);
30 /* Verify that we warn for -Wmemset-transposed-args inside
31    a template.  */
33 char buf[1024];
35 template <class>
36 void test_5 ()
38   __builtin_memset (buf, sizeof buf, 0); // { dg-warning "transposed parameters" }
41 /* Adapted from c-c++-common/memset-array.c; verify that 
42    -Wmemset-elt-size works within a template.  */
44 enum a {
45   a_1,
46   a_2,
47   a_n
49 int t1[20];
50 int t2[a_n];
52 struct s
54   int t[20];
57 template<class>
58 void foo (struct s *s)
60   __builtin_memset (t1, 0, 20); // { dg-warning "element size" }
62   // This case requires reading through an enum value:
63   __builtin_memset (t2, 0, a_n); // { dg-warning "element size" }
65   __builtin_memset (s->t, 0, 20); // { dg-warning "element size" }
67   // These cases require folding of arg2 within a template:
68   __builtin_memset (t2, 0, a_n + 0); // { dg-warning "element size" }
69   __builtin_memset (t2, 0, a_n * 1); // { dg-warning "element size" }