PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-malloc-3.C
blob5f91ee1093437476d74e762151b4be2135240296
1 // Bug c++/84617 - new test cases g++.dg/ext/attr-const.C and
2 // g++.dg/ext/attr-pure.C fail
3 // { dg-do compile }
4 // { dg-options "-O -Wall -fdump-tree-optimized" }
6 static char a[8];
8 void* __attribute__ ((malloc))
9 func_malloc_none (unsigned);
11 void*
12 func_alloc_none (unsigned);         // redeclare with no attribute
14 void func_malloc_none_failed ();
16 void test_func_malloc_none (void)
18   void *p = func_malloc_none (1);
19   if (!p)
20     return;
22   if (p == a)                       // must be false
23     func_malloc_none_failed ();     // should be eliminated
25   // Verify that the call to func_malloc_none_failed() is eliminated.
26   // { dg-final { scan-tree-dump-not "func_malloc_none_failed" "optimized" } }
30 void*
31 func_none_malloc (unsigned);
33 void*  __attribute__ ((malloc))
34 func_none_malloc (unsigned);         // redeclare with an attribute
36 void func_none_malloc_failed ();
38 void test_func_none_malloc (void)
40   void *p = func_none_malloc (1);
41   if (!p)
42     return;
44   if (p == a)                       // must be false
45     func_none_malloc_failed ();     // should be eliminated
47   // Verify that the call to func_none_malloc_failed() is eliminated.
48   // { dg-final { scan-tree-dump-not "func_none_malloc_failed" "optimized" } }
52 template <class>
53 void* __attribute__ ((malloc))
54 templ_malloc_none (unsigned);
56 template <class>
57 void*
58 templ_malloc_none (unsigned);       // redeclare with no attribute
60 void templ_malloc_none_failed ();
62 void test_templ_malloc_none (void)
64   void *p = templ_malloc_none<void>(1);
65   if (!p)
66     return;
68   if (p == a)                       // must be false
69     templ_malloc_none_failed ();    // should be eliminated
71   // Verify that the call to templ_malloc_none_failed() is eliminated.
72   // { dg-final { scan-tree-dump-not "templ_malloc_none_failed" "optimized" } }
75 template <class>
76 void*
77 templ_none_malloc (unsigned);
79 template <class>
80 void* __attribute__ ((malloc))
81 templ_none_malloc (unsigned);       // redeclared with an attribute
83 void templ_none_malloc_failed ();
85 void test_templ_none_malloc (void)
87   void *p = templ_none_malloc<void>(1);
88   if (!p)
89     return;
91   if (p == a)                       // must be false
92     templ_none_malloc_failed ();    // should be eliminated
94   // Verify that the call to templ_none_malloc_failed() is eliminated.
95   // { dg-final { scan-tree-dump-not "templ_none_malloc_failed" "optimized" } }