[C++] PATCH c++/17542 (version 2)
Matt Austern
austern@apple.com
Fri Oct 29 23:31:00 GMT 2004
OK, you like this version better? It gets rid of the phrase "class
key" and instead prints the actual class key that the user supplied.
OK to commit to mainline?
--Matt
Index: gcc/cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.1067
diff -p -r1.1067 cp-tree.h
*** gcc/cp/cp-tree.h 21 Oct 2004 21:23:40 -0000 1.1067
--- gcc/cp/cp-tree.h 29 Oct 2004 22:35:58 -0000
*************** extern const char *expr_as_string (tree
*** 3823,3828 ****
--- 3823,3829 ----
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: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1322
diff -p -r1.1322 decl.c
*** gcc/cp/decl.c 29 Oct 2004 07:16:44 -0000 1.1322
--- gcc/cp/decl.c 29 Oct 2004 22:36:01 -0000
*************** shadow_tag (cp_decl_specifier_seq *decls
*** 3596,3601 ****
--- 3596,3610 ----
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: gcc/cp/error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.268
diff -p -r1.268 error.c
*** gcc/cp/error.c 21 Oct 2004 16:14:29 -0000 1.268
--- gcc/cp/error.c 29 Oct 2004 22:36:01 -0000
*************** static void dump_expr_list (tree, int);
*** 70,76 ****
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);
--- 70,75 ----
*************** dump_typename (tree t, int flags)
*** 396,403 ****
/* Return the name of the supplied aggregate, or enumeral type. */
! static const char *
! class_key_or_enum (tree t)
{
if (TREE_CODE (t) == ENUMERAL_TYPE)
return "enum";
--- 395,402 ----
/* Return the name of the supplied aggregate, or enumeral type. */
! const char *
! class_key_or_enum_as_string (tree t)
{
if (TREE_CODE (t) == ENUMERAL_TYPE)
return "enum";
*************** static void
*** 416,422 ****
dump_aggr_type (tree t, int flags)
{
tree name;
! const char *variety = class_key_or_enum (t);
int typdef = 0;
int tmplate = 0;
--- 415,421 ----
dump_aggr_type (tree t, int flags)
{
tree name;
! const char *variety = class_key_or_enum_as_string (t);
int typdef = 0;
int tmplate = 0;
Index: gcc/testsuite/g++.dg/ext/attrib18.C
===================================================================
RCS file: gcc/testsuite/g++.dg/ext/attrib18.C
diff -N gcc/testsuite/g++.dg/ext/attrib18.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/ext/attrib18.C 29 Oct 2004 22:36:02 -0000
***************
*** 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();
+ };
More information about the Gcc-patches
mailing list