Hi, This patch teaches the C++ frontend how to handle function attributes attached to pointer-to-member-function declarations.
I bootstrapped and regtested this patch on x86_64-unknown-linux-gnu. 2014-04-05 Patrick Palka <patr...@parcs.ath.cx> PR c++/60765 * decl2.c (cplus_decl_attributes): Handle pointer-to-member-function declarations. --- gcc/cp/decl2.c | 10 +++++++++- gcc/testsuite/g++.dg/cpp0x/gen-attrs-36-1.C | 2 +- gcc/testsuite/g++.dg/ext/attrib49.C | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/attrib49.C diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 80f15a4..91a75f3 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1427,7 +1427,15 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) if (TREE_CODE (*decl) == TEMPLATE_DECL) decl = &DECL_TEMPLATE_RESULT (*decl); - decl_attributes (decl, attributes, flags); + if (TREE_TYPE (*decl) && TYPE_PTRMEMFUNC_P (TREE_TYPE (*decl))) + { + attributes + = decl_attributes (decl, attributes, flags | ATTR_FLAG_FUNCTION_NEXT); + decl_attributes (&TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (*decl)), + attributes, flags); + } + else + decl_attributes (decl, attributes, flags); if (TREE_CODE (*decl) == TYPE_DECL) SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl), TREE_TYPE (*decl)); diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36-1.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36-1.C index 2aae9ca..131af36 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36-1.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36-1.C @@ -6,6 +6,6 @@ typedef int (*F [[gnu::warn_unused_result]]) (int); typedef int (*F2 [[gnu::warn_unused_result]]) (int); -typedef int (S::*F3 [[gnu::warn_unused_result]]) (int); // { dg-warning "only applies to function types" } +typedef int (S::*F3 [[gnu::warn_unused_result]]) (int); typedef int [[gnu::warn_unused_result]] (*F5) (int); // { dg-warning "ignored" } diff --git a/gcc/testsuite/g++.dg/ext/attrib49.C b/gcc/testsuite/g++.dg/ext/attrib49.C new file mode 100644 index 0000000..99c6154 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib49.C @@ -0,0 +1,20 @@ +// PR c++/60765 +// { dg-options "-Wall -Wunused-parameter" } + +struct foo +{ +} x; + +void (foo::*g) (int *) __attribute__ ((nonnull (2))); + +void +fun1 (void (foo::*f) (int *) __attribute__ ((nonnull (2)))) +{ + (x.*f) ((int *) 0); // { dg-warning "null argument" } +} + +void +fun2 (void (foo::*f) () __attribute__ ((nonnull, unused))) // { dg-bogus "unused" } +{ + (x.*g) ((int *) 0); // { dg-warning "null argument" } +} -- 1.9.1