* C++ PATCH for c++/52746 (virtual destructors broken in templates)
@ 2012-03-29 2:53 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2012-03-29 2:53 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]
In my fix for PR 48051 I failed to audit all the users of
adjust_result_of_qualified_name_lookup to make sure it wasn't being
called for non-qualified lookups as well; in this case we were calling
it for an explicit destructor call, and now that we set
BASELINK_QUALIFIED_P in that function, we were suppressing virtual
calling semantics inappropriately.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
[-- Attachment #2: 52746.patch --]
[-- Type: text/x-patch, Size: 2445 bytes --]
commit 1f230c968d34b5c48ad50f83e8774de52d04d653
Author: Jason Merrill <jason@redhat.com>
Date: Wed Mar 28 20:59:26 2012 -0400
PR c++/52746
* typeck.c (lookup_destructor): Clear BASELINK_QUALIFIED_P if
we didn't get an explicit scope.
* pt.c (tsubst_baselink): Likewise.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f128947..9b410a7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11814,6 +11814,7 @@ tsubst_baselink (tree baselink, tree object_type,
tree optype;
tree template_args = 0;
bool template_id_p = false;
+ bool qualified = BASELINK_QUALIFIED_P (baselink);
/* A baselink indicates a function from a base class. Both the
BASELINK_ACCESS_BINFO and the base class referenced may
@@ -11862,9 +11863,12 @@ tsubst_baselink (tree baselink, tree object_type,
if (!object_type)
object_type = current_class_type;
- return adjust_result_of_qualified_name_lookup (baselink,
- qualifying_scope,
- object_type);
+
+ if (qualified)
+ baselink = adjust_result_of_qualified_name_lookup (baselink,
+ qualifying_scope,
+ object_type);
+ return baselink;
}
/* Like tsubst_expr for a SCOPE_REF, given by QUALIFIED_ID. DONE is
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b68de52..d2ed940 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2415,6 +2415,11 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
tf_warning_or_error);
expr = (adjust_result_of_qualified_name_lookup
(expr, dtor_type, object_type));
+ if (scope == NULL_TREE)
+ /* We need to call adjust_result_of_qualified_name_lookup in case the
+ destructor names a base class, but we unset BASELINK_QUALIFIED_P so
+ that we still get virtual function binding. */
+ BASELINK_QUALIFIED_P (expr) = false;
return expr;
}
diff --git a/gcc/testsuite/g++.dg/overload/virtual2.C b/gcc/testsuite/g++.dg/overload/virtual2.C
new file mode 100644
index 0000000..c93ba9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/virtual2.C
@@ -0,0 +1,31 @@
+// PR c++/52746
+// { dg-do run }
+
+extern "C" int printf(const char*,...);
+extern "C" void abort();
+bool db;
+
+struct A
+{
+ virtual ~A() {}
+};
+
+struct B : public A
+{
+ virtual ~B() { db = true; }
+};
+
+template<int> void test()
+{
+ B * b = new B;
+ A * a = b;
+ a->~A();
+ ::operator delete(b);
+}
+
+int main()
+{
+ test<0>();
+ if (!db)
+ abort();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-03-29 2:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-29 2:53 C++ PATCH for c++/52746 (virtual destructors broken in templates) 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).