* [PATCH] Fix PR c++/48838
@ 2011-05-03 20:12 Dodji Seketeli
2011-05-03 20:33 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Dodji Seketeli @ 2011-05-03 20:12 UTC (permalink / raw)
To: GCC Patches; +Cc: Jason Merrill
Hello,
This is another fallout of the fix for PR c++/47172, where we started
to make finish_call_expr make member function call expressions that
have a dependent "this" pointer be recognized by
type_dependent_expression_p as being type dependent.
The problem is that a node being a BASELINK is not enough to mean that
it represents a non-static member function, as it can also represent a
static member function. In this patch I try to look at the actual
function wrapped by the BASELINK to make sure it's a non-static
member.
Tested and bootstrapped on x86_64-unknown-linux-gnu against trunk.
Another bootstrap is on it way on the 4.6 branch.
OK to commit to trunk and 4.6 if it passes?
gcc/cp
PR c++/48838
* cp-tree.h (non_static_member_function_p): Declare new function.
* tree.c (non_static_member_function_p): Define it.
* semantics.c (finish_call_expr): Use it.
gcc/testsuite
PR c++/48838
* g++.dg/template/member9.C: New test case.
---
gcc/cp/cp-tree.h | 1 +
gcc/cp/semantics.c | 3 +--
gcc/cp/tree.c | 28 ++++++++++++++++++++++++++++
gcc/testsuite/g++.dg/template/member9.C | 21 +++++++++++++++++++++
4 files changed, 51 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/member9.C
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 961581e..d694e25 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5430,6 +5430,7 @@ extern tree get_fns (tree);
extern tree get_first_fn (tree);
extern tree ovl_cons (tree, tree);
extern tree build_overload (tree, tree);
+extern bool non_static_member_function_p (tree);
extern const char *cxx_printable_name (tree, int);
extern const char *cxx_printable_name_translate (tree, int);
extern tree build_exception_variant (tree, tree);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 815824a..baa8fd4 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2039,8 +2039,7 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
is not included in *ARGS even though it is considered to
be part of the list of arguments. Note that this is
related to CWG issues 515 and 1005. */
- || (((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
- || BASELINK_P (fn))
+ || (non_static_member_function_p (fn)
&& current_class_ref
&& type_dependent_expression_p (current_class_ref)))
{
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 0f2f86c..039f795 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1482,6 +1482,34 @@ build_overload (tree decl, tree chain)
return ovl_cons (decl, chain);
}
+/* Return TRUE if FN is a non-static member function, FALSE otherwise.
+ This function looks into BASELINK and OVERLOAD nodes. */
+
+bool
+non_static_member_function_p (tree fn)
+{
+ if (fn == NULL_TREE)
+ return false;
+
+ if (BASELINK_P (fn))
+ {
+ tree type = TREE_TYPE (fn);
+
+ if (type && TREE_CODE (type) == METHOD_TYPE)
+ return true;
+ else if (type && TREE_CODE (type) == FUNCTION_TYPE)
+ return false;
+ /* This is an overload. Lets look into its current value. */
+ fn = get_fns (BASELINK_FUNCTIONS (fn));
+ }
+
+ if (TREE_CODE (fn) == OVERLOAD)
+ fn = OVL_CURRENT (fn);
+
+ return (DECL_P (fn)
+ && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn));
+}
+
\f
#define PRINT_RING_SIZE 4
diff --git a/gcc/testsuite/g++.dg/template/member9.C b/gcc/testsuite/g++.dg/template/member9.C
new file mode 100644
index 0000000..f15272d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/member9.C
@@ -0,0 +1,21 @@
+// Origin PR c++/48838
+// { dg-do compile }
+
+class DUChainItemSystem
+{
+public:
+
+ template<class T>
+ void registerTypeClass();
+
+ static DUChainItemSystem& self();
+};
+
+template<class T>
+struct DUChainItemRegistrator
+{
+ DUChainItemRegistrator()
+ {
+ DUChainItemSystem::self().registerTypeClass<T>();
+ }
+};
--
1.7.3.4
--
Dodji
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/48838
2011-05-03 20:12 [PATCH] Fix PR c++/48838 Dodji Seketeli
@ 2011-05-03 20:33 ` Jason Merrill
2011-05-05 19:59 ` Dodji Seketeli
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-05-03 20:33 UTC (permalink / raw)
To: Dodji Seketeli; +Cc: GCC Patches
I think using get_first_fn could make non_static_member_function_p a lot
shorter.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/48838
2011-05-03 20:33 ` Jason Merrill
@ 2011-05-05 19:59 ` Dodji Seketeli
2011-05-05 20:47 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Dodji Seketeli @ 2011-05-05 19:59 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
Jason Merrill <jason@redhat.com> writes:
> I think using get_first_fn could make non_static_member_function_p a
> lot shorter.
Like this?
Tested like the previous patch.
gcc/cp
PR c++/48838
* cp-tree.h (non_static_member_function_p): Declare new function.
* tree.c (non_static_member_function_p): Define it.
* semantics.c (finish_call_expr): Use it.
gcc/testsuite
PR c++/48838
* g++.dg/template/member9.C: New test case.
---
gcc/cp/cp-tree.h | 1 +
gcc/cp/semantics.c | 3 +--
gcc/cp/tree.c | 19 +++++++++++++++++++
gcc/testsuite/g++.dg/template/member9.C | 21 +++++++++++++++++++++
4 files changed, 42 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/member9.C
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 961581e..d694e25 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5430,6 +5430,7 @@ extern tree get_fns (tree);
extern tree get_first_fn (tree);
extern tree ovl_cons (tree, tree);
extern tree build_overload (tree, tree);
+extern bool non_static_member_function_p (tree);
extern const char *cxx_printable_name (tree, int);
extern const char *cxx_printable_name_translate (tree, int);
extern tree build_exception_variant (tree, tree);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 815824a..baa8fd4 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2039,8 +2039,7 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
is not included in *ARGS even though it is considered to
be part of the list of arguments. Note that this is
related to CWG issues 515 and 1005. */
- || (((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
- || BASELINK_P (fn))
+ || (non_static_member_function_p (fn)
&& current_class_ref
&& type_dependent_expression_p (current_class_ref)))
{
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 0f2f86c..6115951 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1482,6 +1482,25 @@ build_overload (tree decl, tree chain)
return ovl_cons (decl, chain);
}
+/* Return TRUE if FN is a non-static member function, FALSE otherwise.
+ This function looks into BASELINK and OVERLOAD nodes. */
+
+bool
+non_static_member_function_p (tree fn)
+{
+ if (fn == NULL_TREE)
+ return false;
+
+ if (is_overloaded_fn (fn))
+ fn = get_first_fn (fn);
+ else if (BASELINK_P (fn))
+ return (TREE_TYPE (fn)
+ && TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE);
+
+ return (DECL_P (fn)
+ && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn));
+}
+
\f
#define PRINT_RING_SIZE 4
diff --git a/gcc/testsuite/g++.dg/template/member9.C b/gcc/testsuite/g++.dg/template/member9.C
new file mode 100644
index 0000000..f15272d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/member9.C
@@ -0,0 +1,21 @@
+// Origin PR c++/48838
+// { dg-do compile }
+
+class DUChainItemSystem
+{
+public:
+
+ template<class T>
+ void registerTypeClass();
+
+ static DUChainItemSystem& self();
+};
+
+template<class T>
+struct DUChainItemRegistrator
+{
+ DUChainItemRegistrator()
+ {
+ DUChainItemSystem::self().registerTypeClass<T>();
+ }
+};
--
Dodji
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/48838
2011-05-05 19:59 ` Dodji Seketeli
@ 2011-05-05 20:47 ` Jason Merrill
2011-05-05 22:46 ` Dodji Seketeli
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-05-05 20:47 UTC (permalink / raw)
To: Dodji Seketeli; +Cc: GCC Patches
On 05/05/2011 03:52 PM, Dodji Seketeli wrote:
> + if (is_overloaded_fn (fn))
> + fn = get_first_fn (fn);
> + else if (BASELINK_P (fn))
is_overloaded_fn should be true for a BASELINK.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/48838
2011-05-05 20:47 ` Jason Merrill
@ 2011-05-05 22:46 ` Dodji Seketeli
2011-05-05 23:30 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Dodji Seketeli @ 2011-05-05 22:46 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
Jason Merrill <jason@redhat.com> writes:
> On 05/05/2011 03:52 PM, Dodji Seketeli wrote:
>> + if (is_overloaded_fn (fn))
>> + fn = get_first_fn (fn);
>> + else if (BASELINK_P (fn))
>
> is_overloaded_fn should be true for a BASELINK.
Correct. I should have seen that. I have bootstrapped the patch below
then.
Thanks.
gcc/cp
PR c++/48838
* cp-tree.h (non_static_member_function_p): Declare new function.
* tree.c (non_static_member_function_p): Define it.
* semantics.c (finish_call_expr): Use it.
gcc/testsuite
PR c++/48838
* g++.dg/template/member9.C: New test case.
---
gcc/cp/cp-tree.h | 1 +
gcc/cp/semantics.c | 3 +--
gcc/cp/tree.c | 16 ++++++++++++++++
gcc/testsuite/g++.dg/template/member9.C | 21 +++++++++++++++++++++
4 files changed, 39 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/member9.C
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index fcb715c..9d13393 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5432,6 +5432,7 @@ extern tree get_fns (tree);
extern tree get_first_fn (tree);
extern tree ovl_cons (tree, tree);
extern tree build_overload (tree, tree);
+extern bool non_static_member_function_p (tree);
extern const char *cxx_printable_name (tree, int);
extern const char *cxx_printable_name_translate (tree, int);
extern tree build_exception_variant (tree, tree);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 8bf5a52..a2b24d3 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2039,8 +2039,7 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
is not included in *ARGS even though it is considered to
be part of the list of arguments. Note that this is
related to CWG issues 515 and 1005. */
- || (((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
- || BASELINK_P (fn))
+ || (non_static_member_function_p (fn)
&& current_class_ref
&& type_dependent_expression_p (current_class_ref)))
{
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 3230393..d636548 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1480,6 +1480,22 @@ build_overload (tree decl, tree chain)
return ovl_cons (decl, chain);
}
+/* Return TRUE if FN is a non-static member function, FALSE otherwise.
+ This function looks into BASELINK and OVERLOAD nodes. */
+
+bool
+non_static_member_function_p (tree fn)
+{
+ if (fn == NULL_TREE)
+ return false;
+
+ if (is_overloaded_fn (fn))
+ fn = get_first_fn (fn);
+
+ return (DECL_P (fn)
+ && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn));
+}
+
\f
#define PRINT_RING_SIZE 4
diff --git a/gcc/testsuite/g++.dg/template/member9.C b/gcc/testsuite/g++.dg/template/member9.C
new file mode 100644
index 0000000..f15272d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/member9.C
@@ -0,0 +1,21 @@
+// Origin PR c++/48838
+// { dg-do compile }
+
+class DUChainItemSystem
+{
+public:
+
+ template<class T>
+ void registerTypeClass();
+
+ static DUChainItemSystem& self();
+};
+
+template<class T>
+struct DUChainItemRegistrator
+{
+ DUChainItemRegistrator()
+ {
+ DUChainItemSystem::self().registerTypeClass<T>();
+ }
+};
--
Dodji
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/48838
2011-05-05 22:46 ` Dodji Seketeli
@ 2011-05-05 23:30 ` Jason Merrill
0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2011-05-05 23:30 UTC (permalink / raw)
To: Dodji Seketeli; +Cc: GCC Patches
OK.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-05 23:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-03 20:12 [PATCH] Fix PR c++/48838 Dodji Seketeli
2011-05-03 20:33 ` Jason Merrill
2011-05-05 19:59 ` Dodji Seketeli
2011-05-05 20:47 ` Jason Merrill
2011-05-05 22:46 ` Dodji Seketeli
2011-05-05 23:30 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).