c++: Add testcase for DR 2604

Message ID Y3Ip4JHD7cg8W8MG@tucnak
State Accepted
Headers
Series c++: Add testcase for DR 2604 |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Jakub Jelinek Nov. 14, 2022, 11:43 a.m. UTC
  Hi!

Working virtually out of Baker Island.

As the following testcase shows, I think we don't inherit template's
attributes into specializations.

Tested on x86_64-linux, ok for trunk?

2022-11-13  Jakub Jelinek  <jakub@redhat.com>

	* g++.dg/DRs/dr2604.C: New test.


	Jakub
  

Comments

Jason Merrill Nov. 14, 2022, 11:12 p.m. UTC | #1
On 11/14/22 01:43, Jakub Jelinek wrote:
> Hi!
> 
> Working virtually out of Baker Island.
> 
> As the following testcase shows, I think we don't inherit template's
> attributes into specializations.
> 
> Tested on x86_64-linux, ok for trunk?

OK.

> 2022-11-13  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* g++.dg/DRs/dr2604.C: New test.
> 
> --- gcc/testsuite/g++.dg/DRs/dr2604.C.jj	2022-11-13 23:39:45.725712300 -1200
> +++ gcc/testsuite/g++.dg/DRs/dr2604.C	2022-11-13 23:39:38.712807673 -1200
> @@ -0,0 +1,53 @@
> +// DR 2604 - Attributes for an explicit specialization.
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-Wunused-parameter" }
> +
> +template<typename>
> +[[noreturn]] void
> +foo ([[maybe_unused]] int i)
> +{
> +  for (;;);
> +}
> +
> +template<>
> +void
> +foo<int> (int i)	// { dg-warning "unused parameter 'i'" }
> +{
> +}
> +
> +template<typename>
> +void
> +bar (int i)		// { dg-warning "unused parameter 'i'" }
> +{
> +}
> +
> +template<>
> +[[noreturn]] void
> +bar<int> ([[maybe_unused]] int i)
> +{
> +  for (;;);
> +}
> +
> +[[noreturn]] void
> +baz ()
> +{
> +  foo<long> (0);
> +}
> +
> +[[noreturn]] void
> +qux ()
> +{
> +  foo<int> (0);
> +}			// { dg-warning "'noreturn' function does return" }
> +
> +[[noreturn]] void
> +garply ()
> +{
> +  bar<long> (0);
> +}			// { dg-warning "'noreturn' function does return" }
> +
> +[[noreturn]] void
> +corge ()
> +{
> +  bar<int> (0);
> +}
> 
> 	Jakub
>
  

Patch

--- gcc/testsuite/g++.dg/DRs/dr2604.C.jj	2022-11-13 23:39:45.725712300 -1200
+++ gcc/testsuite/g++.dg/DRs/dr2604.C	2022-11-13 23:39:38.712807673 -1200
@@ -0,0 +1,53 @@ 
+// DR 2604 - Attributes for an explicit specialization.
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-parameter" }
+
+template<typename>
+[[noreturn]] void
+foo ([[maybe_unused]] int i)
+{
+  for (;;);
+}
+
+template<>
+void
+foo<int> (int i)	// { dg-warning "unused parameter 'i'" }
+{
+}
+
+template<typename>
+void
+bar (int i)		// { dg-warning "unused parameter 'i'" }
+{
+}
+
+template<>
+[[noreturn]] void
+bar<int> ([[maybe_unused]] int i)
+{
+  for (;;);
+}
+
+[[noreturn]] void
+baz ()
+{
+  foo<long> (0);
+}
+
+[[noreturn]] void
+qux ()
+{
+  foo<int> (0);
+}			// { dg-warning "'noreturn' function does return" }
+
+[[noreturn]] void
+garply ()
+{
+  bar<long> (0);
+}			// { dg-warning "'noreturn' function does return" }
+
+[[noreturn]] void
+corge ()
+{
+  bar<int> (0);
+}