C++ PATCH to warn about ignored attributes

Message ID 4F3B0F81.5040402@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 15, 2012, 1:50 a.m.
While looking at PR 51930, I discovered that we were silently ignoring 
attributes on explicit instantiations; this patch warns about this. 
This isn't exactly a regression, but the submitter ran into it as a 
result of a behavior change in 4.7, and the patch is extremely safe, so 
I think it should go in.

Tested x86_64-pc-linux-gnu, applying to trunk.


commit dd0af86e2c58357e5aa83d9791e6bc6ae9c2a418
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 14 17:25:35 2012 -0800

    	* parser.c (cp_parser_explicit_instantiation): Give a warning
    	for ignored attributes on explicit class instantiation.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 491f48e..3e2be97 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13122,6 +13122,9 @@  cp_parser_explicit_instantiation (cp_parser* parser)
       tree type;
       type = check_tag_decl (&decl_specifiers);
+      if (decl_specifiers.attributes)
+	warning (OPT_Wattributes,
+		 "attributes ignored on explicit type instantiation");
       /* Turn access control back on for names used during
 	 template instantiation.  */
       pop_deferring_access_checks ();
diff --git a/gcc/testsuite/g++.dg/ext/attrib43.C b/gcc/testsuite/g++.dg/ext/attrib43.C
new file mode 100644
index 0000000..fe9f072
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib43.C
@@ -0,0 +1,5 @@ 
+template <class T> struct A { };
+__attribute__ ((packed))
+struct A<int>;			// { dg-warning "attributes ignored" }