From 29c593c739d0a114718419c4e264674a3cac24c0 Mon Sep 17 00:00:00 2001 From: Le-Chun Wu Date: Tue, 20 Jan 2009 21:20:57 +0000 Subject: Fix an issue in cp_parser_init_declarator. When calling grok_field, besides prefix_attributes, we should also pass in the attributes that were just parsed and returned from cp_parser_attributes_opt. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/thread-annotations@143528 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog.lock-annotations | 5 +++++ gcc/cp/parser.c | 2 +- gcc/testsuite/ChangeLog.lock-annotations | 5 +++++ .../g++.dg/thread-ann/thread_annot_lock-37.C | 23 ++++++++++++++++++++++ .../g++.dg/thread-ann/thread_annot_lock-38.C | 23 ++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-37.C create mode 100644 gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-38.C diff --git a/gcc/ChangeLog.lock-annotations b/gcc/ChangeLog.lock-annotations index 29343c734ff..6b358e4b70d 100644 --- a/gcc/ChangeLog.lock-annotations +++ b/gcc/ChangeLog.lock-annotations @@ -1,3 +1,8 @@ +2009-01-20 Le-Chun Wu + + * cp/parser.c (cp_parser_init_declarator): Pass both prefix_attributes + and attributes to grokfield. + 2009-01-07 Le-Chun Wu * tree-threadsafe-analyze.c (lock_set_contains): Check the lock set diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7b89ab8c688..e73f8b61d3b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12921,7 +12921,7 @@ cp_parser_init_declarator (cp_parser* parser, decl = grokfield (declarator, decl_specifiers, initializer, !is_non_constant_init, /*asmspec=*/NULL_TREE, - prefix_attributes); + chainon (prefix_attributes, attributes)); if (decl && TREE_CODE (decl) == FUNCTION_DECL) cp_parser_save_default_args (parser, decl); } diff --git a/gcc/testsuite/ChangeLog.lock-annotations b/gcc/testsuite/ChangeLog.lock-annotations index 6616966218d..8f5ffcd89b0 100644 --- a/gcc/testsuite/ChangeLog.lock-annotations +++ b/gcc/testsuite/ChangeLog.lock-annotations @@ -1,3 +1,8 @@ +2009-01-20 Le-Chun Wu + + * g++.dg/thread-ann/thread_annot_lock-37.C: New test. + * g++.dg/thread-ann/thread_annot_lock-38.C: New test. + 2009-01-07 Le-Chun Wu * g++.dg/thread-ann/thread_annot_lock-35.C: New test. diff --git a/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-37.C b/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-37.C new file mode 100644 index 00000000000..b4c2a1c71ea --- /dev/null +++ b/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-37.C @@ -0,0 +1,23 @@ +// Test the case where a template member function is annotated with lock +// attributes in a non-template class. +// { dg-do compile } +// { dg-options "-Wthread-safety -Wthread-unsupported-lock-name -O" } + +#include "thread_annot_common.h" + +class Foo { + public: + void func1(int y) EXCLUSIVE_LOCKS_REQUIRED(mu_); + template void func2(T x) LOCKS_EXCLUDED(mu_); + Mutex mu_; +}; + +Foo *foo; + +int main() +{ + foo->mu_.Lock(); + foo->func1(5); + foo->func2(5); // { dg-warning "Cannot call function 'func2' with lock 'foo->mu_' held" } + foo->mu_.Unlock(); +} diff --git a/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-38.C b/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-38.C new file mode 100644 index 00000000000..9140a4911a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-38.C @@ -0,0 +1,23 @@ +// Test the case where a template member function is annotated with lock +// attributes in a non-template class. +// This is a "good" test that should not incur any compiler warnings. +// { dg-do compile } +// { dg-options "-Wthread-safety -Wthread-unsupported-lock-name -O" } + +#include "thread_annot_common.h" + +class Foo { + public: + void func1(int y) LOCKS_EXCLUDED(mu_); + template void func2(T x) LOCKS_EXCLUDED(mu_); + private: + Mutex mu_; +}; + +Foo *foo; + +int main() +{ + foo->func1(5); + foo->func2(5); +} -- cgit v1.2.3