PR c++/12333 - X::~X() with implicit this->.
authorJason Merrill <jason@redhat.com>
Wed, 18 Dec 2019 12:44:34 +0000 (07:44 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 18 Dec 2019 12:44:34 +0000 (07:44 -0500)
this->X::~X() is handled by finish_class_member_access_expr and its
lookup_destructor subroutine; let's use it in cp_parser_lookup_name for the
case where this-> is implicit.

I tried replacing the other destructor code here with just the call to
lookup_destructor, but that regressed handling of naming the destructor
outside a non-static member function.

* parser.c (cp_parser_lookup_name): Use lookup_destructor.
* typeck.c (lookup_destructor): No longer static.

From-SVN: r279522

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/lookup/dtor1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/dtor3.C

index eefe5bf45389879ae2f23b4f8f015bfdffc03925..8b1d4e036d8fcfb3f256bea2e5910270d03a51a5 100644 (file)
@@ -1,3 +1,9 @@
+2019-12-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/12333 - X::~X() with implicit this->.
+       * parser.c (cp_parser_lookup_name): Use lookup_destructor.
+       * typeck.c (lookup_destructor): No longer static.
+
 2019-12-17  Martin Sebor  <msebor@redhat.com>
 
        PR c++/61339
index b47698e1d0ce83a07df3a29bf1c1cffa3de29b5a..c35ed9abe08f60e7da906e39fbcd0cfbb1291284 100644 (file)
@@ -7500,6 +7500,7 @@ extern tree build_class_member_access_expr      (cp_expr, tree, tree, bool,
                                                 tsubst_flags_t);
 extern tree finish_class_member_access_expr     (cp_expr, tree, bool,
                                                 tsubst_flags_t);
+extern tree lookup_destructor                  (tree, tree, tree, tsubst_flags_t);
 extern tree build_x_indirect_ref               (location_t, tree,
                                                 ref_operator,
                                                 tsubst_flags_t);
index f61089934dfe6bcd8865251dbb210f0c3b320cc7..de7928340505716e49fc0ddb0ab59a647c6d6cd6 100644 (file)
@@ -27939,6 +27939,11 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
       if (!type || !CLASS_TYPE_P (type))
        return error_mark_node;
 
+      /* In a non-static member function, check implicit this->.  */
+      if (current_class_ref)
+       return lookup_destructor (current_class_ref, parser->scope, name,
+                                 tf_warning_or_error);
+
       if (CLASSTYPE_LAZY_DESTRUCTOR (type))
        lazily_declare_fn (sfk_destructor, type);
 
index d3814585e3ffa1a3b6bc5f010de2c6541d510917..669ca83cccff6f60da4dade600e84682c68e6098 100644 (file)
@@ -59,7 +59,6 @@ static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t);
 static void casts_away_constness_r (tree *, tree *, tsubst_flags_t);
 static bool casts_away_constness (tree, tree, tsubst_flags_t);
 static bool maybe_warn_about_returning_address_of_local (tree);
-static tree lookup_destructor (tree, tree, tree, tsubst_flags_t);
 static void error_args_num (location_t, tree, bool);
 static int convert_arguments (tree, vec<tree, va_gc> **, tree, int,
                               tsubst_flags_t);
@@ -2696,7 +2695,7 @@ build_class_member_access_expr (cp_expr object, tree member,
 /* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
    SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type.  */
 
-static tree
+tree
 lookup_destructor (tree object, tree scope, tree dtor_name,
                   tsubst_flags_t complain)
 {
diff --git a/gcc/testsuite/g++.dg/lookup/dtor1.C b/gcc/testsuite/g++.dg/lookup/dtor1.C
new file mode 100644 (file)
index 0000000..2912287
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/12333
+
+struct A { };
+
+struct X { 
+  void f () {
+    X::~X ();
+    this->~X();
+    ~X();                      // { dg-error "" "unary ~" }
+    A::~A ();                  // { dg-error "" }
+    X::~A ();                          // { dg-error "" }
+  }
+};
index 3041ae4a568f9ee93e654a36a9a79b251a96c9ef..6121bed7e8be64b5395476e8668deaa04cb268c4 100644 (file)
@@ -4,13 +4,13 @@
 //  destructor call.
 
 struct Y { 
-  ~Y() {}      // { dg-bogus "note" "implemented DR272" { xfail *-*-* } }  
+  ~Y() {}      // { dg-bogus "note" "implemented DR272" }  
 };
 
 struct X : Y { 
-  ~X() {}      // { dg-bogus "note" "implemented DR272" { xfail *-*-* } }  
+  ~X() {}      // { dg-bogus "note" "implemented DR272" }  
   void f() { 
-    X::~X();   // { dg-bogus "" "implemented DR272" { xfail *-*-* } }  
-    Y::~Y();   // { dg-bogus "" "implemented DR272" { xfail *-*-* } }  
+    X::~X();   // { dg-bogus "" "implemented DR272" }  
+    Y::~Y();   // { dg-bogus "" "implemented DR272" }  
   } 
 };