[PR c++/84702] ICE with default tmpl arg of overload set
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-malloc.C
blob3cbb41407ea86773a00cc8a7d769df561834b378
1 // Bug c++/83503 - bogus -Wattributes for const and pure on function template
2 // specialization
3 // Test to verify that an explicit template specifialization does not
4 // "inherit" attribute malloc from a primary template declared with one.
5 // { dg-do compile }
6 // { dg-options "-O -Wall -fdump-tree-optimized" }
8 template <class>
9 void* __attribute__ ((malloc))
10 fmalloc (unsigned);
12 template <>
13 void*
14 fmalloc<int>(unsigned);       // { dg-warning "may be missing attributes" }
16 static char a[8];
18 void fmalloc_void_malloc ();
19 void fmalloc_int_not_malloc ();
21 void test_fmalloc_primary (void)
23   void *p = fmalloc<void>(1);
24   if (!p)
25     return;
27   if (p == a)                     // must be false
28     fmalloc_void_malloc ();       // should be eliminated
30   // Verify that the call to fmalloc_void_malloc() is eliminated.
31   // { dg-final { scan-tree-dump-not "fmalloc_void_malloc" "optimized" } }
35 void test_fmalloc_spec_none (void)
37   void *p = fmalloc<int>(1);
38   if (!p)
39     return;
41   if (p == a)                     // can be true
42     fmalloc_int_not_malloc ();    // must not be eliminated
44   // Verify that the call to fmalloc_int_not_malloc() is retained.
45   // { dg-final { scan-tree-dump-times "fmalloc_int_not_malloc" 1 "optimized" } }
48 template <>
49 void*
50 fmalloc<long>(unsigned);          // { dg-warning "may be missing attributes" }
52 template <>
53 void* __attribute__ ((malloc))
54 fmalloc<long>(unsigned);
56 void fmalloc_long_malloc ();
58 void test_fmalloc_spec_malloc (void)
60   void *p = fmalloc<long>(1);
61   if (!p)
62     return;
64   if (p == a)                     // can be true
65     fmalloc_long_malloc ();       // must not be eliminated
67   // Verify that the call to fmalloc_long_malloc() is eliminated.
68   // { dg-final { scan-tree-dump-not "fmalloc_long_malloc" "optimized" } }