re PR c++/17542 (Visibility attribute ignored when it precedes class head)
authorMatt Austern <austern@apple.com>
Sat, 30 Oct 2004 21:17:31 +0000 (21:17 +0000)
committerMatt Austern <austern@gcc.gnu.org>
Sat, 30 Oct 2004 21:17:31 +0000 (21:17 +0000)
PR c++/17542
* cp-tree.h (class_key_or_enum_as_string): Declare.
* error.c (class_key_or_enum): Rename to class_key_or_enum_as_string
and remove static qualifier.
* decl.c (shadow_tag): Warn about ignored attributes in class/struct/
union/enum declaration.
* g++.dg/ext/attrib18.C: New test.

From-SVN: r89898

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/attrib18.C [new file with mode: 0644]

index b569b94681e733c88e0d77cd6a84fdef3f39359c..fee23b58b78563e259505aec011a4dc101accd29 100644 (file)
@@ -1,3 +1,12 @@
+1004-10-28  Matt Austern  <austern@apple.com>
+
+       PR c++/17542
+       * cp-tree.h (class_key_or_enum_as_string): Declare.
+       * error.c (class_key_or_enum): Rename to class_key_or_enum_as_string
+       and remove static qualifier.
+       * decl.c (shadow_tag): Warn about ignored attributes in class/struct/
+       union/enum declaration.
+       
 2004-10-29  Kazu Hirata  <kazu@cs.umass.edu>
 
        * pt.c: Fix a comment typo.
index 580a73b4db87ddd4f7c2a08637df4813cd2453c4..307809fabdc6723b0487db0e7a0356715bdb3681 100644 (file)
@@ -3823,6 +3823,7 @@ extern const char *expr_as_string         (tree, int);
 extern const char *context_as_string            (tree, int);
 extern const char *lang_decl_name              (tree, int);
 extern const char *language_to_string           (enum languages);
+extern const char *class_key_or_enum_as_string  (tree);
 extern void print_instantiation_context         (void);
 
 /* in except.c */
index c435e488bb4affa96e5abe47da6c155b1f2a6ba8..63227df57396325f6f42c43d36300c00b739db9e 100644 (file)
@@ -3596,6 +3596,15 @@ shadow_tag (cp_decl_specifier_seq *declspecs)
   if (!t)
     return NULL_TREE;
 
+  if (declspecs->attributes)
+    {
+      cp_warning_at ("attribute ignored in declaration of %q#T", t);
+      cp_warning_at ("attribute for %q#T must follow the %qs keyword",
+                    t,
+                    class_key_or_enum_as_string (t));
+
+    }
+
   maybe_process_partial_specialization (t);
 
   /* This is where the variables in an anonymous union are
index 9f79a26253c095dc804bd3fa35292dcf1a8a9f71..a5861124947b9bcb063979d9e77a05ef8b8dc5c3 100644 (file)
@@ -70,7 +70,6 @@ static void dump_expr_list (tree, int);
 static void dump_global_iord (tree);
 static void dump_parameters (tree, int);
 static void dump_exception_spec (tree, int);
-static const char *class_key_or_enum (tree);
 static void dump_template_argument (tree, int);
 static void dump_template_argument_list (tree, int);
 static void dump_template_parameter (tree, int);
@@ -396,8 +395,8 @@ dump_typename (tree t, int flags)
 
 /* Return the name of the supplied aggregate, or enumeral type.  */
 
-static const char *
-class_key_or_enum (tree t)
+const char *
+class_key_or_enum_as_string (tree t)
 {
   if (TREE_CODE (t) == ENUMERAL_TYPE)
     return "enum";
@@ -416,7 +415,7 @@ static void
 dump_aggr_type (tree t, int flags)
 {
   tree name;
-  const char *variety = class_key_or_enum (t);
+  const char *variety = class_key_or_enum_as_string (t);
   int typdef = 0;
   int tmplate = 0;
 
index 95e2a9d49928bd30006135062794e2dd4478a46b..3255d473b82d864b7122b0d32681ff59a9fdcf1b 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-30  Matt Austern  <austern@apple.com>
+
+       PR c++/17542
+       * g++.dg/ext/attrib18.C: New test.
+       
 2004-10-30  Roger Sayle  <roger@eyesopen.com>
 
        PR middle-end/18096
diff --git a/gcc/testsuite/g++.dg/ext/attrib18.C b/gcc/testsuite/g++.dg/ext/attrib18.C
new file mode 100644 (file)
index 0000000..0c3a072
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/17542
+// Test that we warn when an attribute preceding the class-key is ignored.
+// { dg-do compile }
+
+__attribute__ ((packed)) struct A
+{                              // { dg-warning "attribute" }
+  char c;
+  int x;
+  void f();
+};