PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-returns-nonnull.C
blobf75f32e46e884e616e03597d842aca3e9e021049
1 // Bug c++/83871 - wrong code due to attributes on distinct template
2 // specializations
3 // Test to verify that an explicit function template specifialization
4 // does not "inherit" attribute nonnull from an argument declared with
5 // one in the primary template.
6 // { dg-do compile }
7 // { dg-options "-O -Wall -fdump-tree-optimized" }
9 template <class T>
10 void* __attribute__ ((returns_nonnull))
11 g ();
13 template <>
14 void*
15 g<int>();
17 extern void g_void_returns_nonnull ();
18 extern void g_int_may_return_null ();
20 void test_returns_nonnull ()
22   void *p = g<void>();
23   if (!p)
24     g_void_returns_nonnull ();
26   (void)&p;
29 void test_may_return_null ()
31   void *p = g<int>();
32   if (!p)
33     g_int_may_return_null ();
35   (void)&p;
39 // Verify that the call to g_void_returns_nonnull() is eliminated but
40 // the call to g_int_may_return_null() is retained.
41 // { dg-final { scan-tree-dump-not "g_void_returns_nonnull" "optimized" } }
42 // { dg-final { scan-tree-dump-times "g_int_may_return_null" 1 "optimized" } }