From 5c3a10fbc1d4e91287b635d6ff068c8f80dff8cd Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 11 May 2016 17:07:37 +0000 Subject: re PR c++/71024 (Missing warning for contradictory attributes) PR c++/71024 * c-common.c (diagnose_mismatched_attributes): New function. * c-common.h (diagnose_mismatched_attributes): Declare. * c-decl.c (diagnose_mismatched_decls): Factor out code to diagnose_mismatched_attributes and call it. * decl.c (duplicate_decls): Call diagnose_mismatched_decls. * c-c++-common/attributes-3.c: New test. From-SVN: r236129 --- gcc/c/c-decl.c | 50 +------------------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) (limited to 'gcc/c/c-decl.c') diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 9c09536..6ba0e0e 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -2227,55 +2227,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, } if (TREE_CODE (newdecl) == FUNCTION_DECL) - { - tree a1 = lookup_attribute ("optimize", DECL_ATTRIBUTES (olddecl)); - tree a2 = lookup_attribute ("optimize", DECL_ATTRIBUTES (newdecl)); - /* An optimization attribute applied on a declaration after the - definition is likely not what the user wanted. */ - if (a2 != NULL_TREE - && DECL_SAVED_TREE (olddecl) != NULL_TREE - && (a1 == NULL_TREE || !attribute_list_equal (a1, a2))) - warned |= warning (OPT_Wattributes, - "optimization attribute on %qD follows " - "definition but the attribute doesn%'t match", - newdecl); - - /* Diagnose inline __attribute__ ((noinline)) which is silly. */ - if (DECL_DECLARED_INLINE_P (newdecl) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) - warned |= warning (OPT_Wattributes, - "inline declaration of %qD follows " - "declaration with attribute noinline", newdecl); - else if (DECL_DECLARED_INLINE_P (olddecl) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute " - "noinline follows inline declaration ", newdecl); - else if (lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)) - && lookup_attribute ("always_inline", DECL_ATTRIBUTES (olddecl))) - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute " - "%qs follows declaration with attribute %qs", - newdecl, "noinline", "always_inline"); - else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (newdecl)) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute " - "%qs follows declaration with attribute %qs", - newdecl, "always_inline", "noinline"); - else if (lookup_attribute ("cold", DECL_ATTRIBUTES (newdecl)) - && lookup_attribute ("hot", DECL_ATTRIBUTES (olddecl))) - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute %qs follows " - "declaration with attribute %qs", newdecl, "cold", - "hot"); - else if (lookup_attribute ("hot", DECL_ATTRIBUTES (newdecl)) - && lookup_attribute ("cold", DECL_ATTRIBUTES (olddecl))) - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute %qs follows " - "declaration with attribute %qs", newdecl, "hot", - "cold"); - } + warned |= diagnose_mismatched_attributes (olddecl, newdecl); else /* PARM_DECL, VAR_DECL */ { /* Redeclaration of a parameter is a constraint violation (this is -- cgit v1.1