This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How to determine if a decl is a class member in GCC
- From: "Le-Chun Wu" <lcwu at google dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 18 Jul 2008 10:22:15 -0700
- Subject: How to determine if a decl is a class member in GCC
Hi,
In my attribute handlers that handle the new thread-safety attributes
(in c-common.c), I need to check if a decl is a class member. How do
people do that? My original code was checking if a decl is a
FIELD_DECL but that doesn't work for static members. I also tried to
use DECL_CONTEXT but it is not set (in the C++ front-end) for data
members. (I was able to use DECL_CONTEXT for member functions,
though.) Is there any other way that I should use?
BTW, as an experiment, I went ahead and made the following change in
C++ front-end to set the DECL_CONTEXT of class data members. The patch
appears to work and doesn't seem to break any g++ and gcc regression
tests. (I will be running gdb testsuite later.) I think there must be
a reason why the DECL_CONTEXT of data members wasn't set in the
front-end, but it's not clear to my why. Can someone kindly explain
why that is and whether the patch is OK?
Thanks,
Le-chun
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 137849)
+++ cp/decl.c (working copy)
@@ -9074,6 +9074,11 @@ grokdeclarator (const cp_declarator *dec
if (thread_p)
DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
+
+ /* Since a static class data member is a VAR_DECL (instead of
+ a FIELD_DECL), setting the decl_context here allows us to
+ tell if it is a class member. */
+ DECL_CONTEXT (decl) = ctype ? ctype : current_class_type;
}
else
{