PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-optimize.C
blob481cf3f590c3badc9b53abba36b023e2c9263db0
1 // Bug c++/83871 - wrong code due to attributes on distinct template
2 // specializations
3 // Test to verify that an explicit template specifialization does not
4 // "inherit" attribute optimize from a primary template declared with
5 // one.
6 // { dg-do compile }
7 // { dg-options "-O2 -Wall -fdump-tree-optimized" }
9 enum Special { };
11 void foptimize_none_primary_failed ();
13 template <class T>
14 void __attribute__ ((optimize ("no-printf-return-value")))
15 foptimize_none ()
17   // The call to snprintf and the test should be retained.
18   if (2 != __builtin_snprintf (0, 0, "%hhx", 0x12))
19     foptimize_none_primary_failed ();
22 void foptimize_none_special_failed ();
24 template <>
25 inline void
26 foptimize_none<Special>()
28   // The whole if statement should be eliminated.
29   if (3 != __builtin_snprintf (0, 0, "1%hhx", 0x12))
30     foptimize_none_special_failed ();
33 void test_primary ()
35   foptimize_none<void>();
36   // { dg-final { scan-tree-dump-times "foptimize_none_primary_failed *\\(\\)" 1 "optimized" } }
39 void test_special ()
41   // Should be eliminated.
42   foptimize_none<Special>();
43 // { dg-final { scan-tree-dump-not "foptimize_none_special_failed *\\(\\)" "optimized" } }
46 // { dg-final { scan-tree-dump-times "__builtin_snprintf" 1 "optimized" } }