aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLe-Chun Wu <lcwu@google.com>2009-01-20 21:20:57 +0000
committerLe-Chun Wu <lcwu@google.com>2009-01-20 21:20:57 +0000
commit29c593c739d0a114718419c4e264674a3cac24c0 (patch)
treef38f5d760e82b4b3d4a3f1962a62e1924c6b0cda
parente2405c54e1fd30965d9e50cca3aee8d623a408e9 (diff)
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
-rw-r--r--gcc/ChangeLog.lock-annotations5
-rw-r--r--gcc/cp/parser.c2
-rw-r--r--gcc/testsuite/ChangeLog.lock-annotations5
-rw-r--r--gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-37.C23
-rw-r--r--gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-38.C23
5 files changed, 57 insertions, 1 deletions
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 <lcwu@google.com>
+
+ * cp/parser.c (cp_parser_init_declarator): Pass both prefix_attributes
+ and attributes to grokfield.
+
2009-01-07 Le-Chun Wu <lcwu@google.com>
* 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 <lcwu@google.com>
+
+ * 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 <lcwu@google.com>
* 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 <typename T> 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 <typename T> void func2(T x) LOCKS_EXCLUDED(mu_);
+ private:
+ Mutex mu_;
+};
+
+Foo *foo;
+
+int main()
+{
+ foo->func1(5);
+ foo->func2(5);
+}