re PR c++/84222 ([[deprecated]] class complains about internal class usage)
authorJakub Jelinek <jakub@redhat.com>
Thu, 15 Mar 2018 17:45:01 +0000 (18:45 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 15 Mar 2018 17:45:01 +0000 (18:45 +0100)
PR c++/84222
* cp-tree.h (cp_warn_deprecated_use): Declare.
* tree.c (cp_warn_deprecated_use): New function.
* typeck2.c (build_functional_cast): Use it.
* decl.c (grokparms): Likewise.
(grokdeclarator): Likewise.  Temporarily push nested class scope
around grokparms call for out of class member definitions.

* g++.dg/warn/deprecated.C (T::member3): Change dg-warning to dg-bogus.
* g++.dg/warn/deprecated-6.C (T::member3): Likewise.
* g++.dg/warn/deprecated-13.C: New test.

From-SVN: r258568

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/tree.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/deprecated-13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/deprecated-6.C
gcc/testsuite/g++.dg/warn/deprecated.C

index dc7708ba499e447f5127dcecbb7fbc76a89f857b..a4f845a061b008070d038706b7d32d9e15a57581 100644 (file)
@@ -1,3 +1,13 @@
+2018-03-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84222
+       * cp-tree.h (cp_warn_deprecated_use): Declare.
+       * tree.c (cp_warn_deprecated_use): New function.
+       * typeck2.c (build_functional_cast): Use it.
+       * decl.c (grokparms): Likewise.
+       (grokdeclarator): Likewise.  Temporarily push nested class scope
+       around grokparms call for out of class member definitions.
+
 2018-03-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/84820 - no error for invalid qualified-id.
index 186a37eea6b3da8407c05d8afb4561450c42ef03..99c51a89092242412d92a8d5566ea1164c71cffa 100644 (file)
@@ -7064,6 +7064,7 @@ extern tree cxx_copy_lang_qualifiers              (const_tree, const_tree);
 
 extern void cxx_print_statistics               (void);
 extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t);
+extern void cp_warn_deprecated_use             (tree);
 
 /* in ptree.c */
 extern void cxx_print_xnode                    (FILE *, tree, int);
index 45daccda9164d11c7235f71c40a4dc4eb277eece..98f762e5253b6f8549fd004906294a8fb6c89e12 100644 (file)
@@ -10448,7 +10448,7 @@ grokdeclarator (const cp_declarator *declarator,
      suppress reports of deprecated items.  */
   if (type && TREE_DEPRECATED (type)
       && deprecated_state != DEPRECATED_SUPPRESS)
-    warn_deprecated_use (type, NULL_TREE);
+    cp_warn_deprecated_use (type);
   if (type && TREE_CODE (type) == TYPE_DECL)
     {
       typedef_decl = type;
@@ -10456,7 +10456,7 @@ grokdeclarator (const cp_declarator *declarator,
       if (TREE_DEPRECATED (type)
          && DECL_ARTIFICIAL (typedef_decl)
          && deprecated_state != DEPRECATED_SUPPRESS)
-       warn_deprecated_use (type, NULL_TREE);
+       cp_warn_deprecated_use (type);
     }
   /* No type at all: default to `int', and set DEFAULTED_INT
      because it was not a user-defined typedef.  */
@@ -11271,8 +11271,18 @@ grokdeclarator (const cp_declarator *declarator,
                  explicitp = 2;
              }
 
-           arg_types = grokparms (declarator->u.function.parameters,
-                                  &parms);
+           tree pushed_scope = NULL_TREE;
+           if (funcdecl_p
+               && decl_context != FIELD
+               && inner_declarator->u.id.qualifying_scope
+               && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
+             pushed_scope
+               = push_scope (inner_declarator->u.id.qualifying_scope);
+
+           arg_types = grokparms (declarator->u.function.parameters, &parms);
+
+           if (pushed_scope)
+             pop_scope (pushed_scope);
 
            if (inner_declarator
                && inner_declarator->kind == cdk_id
@@ -12799,7 +12809,7 @@ grokparms (tree parmlist, tree *parms)
            {
              tree deptype = type_is_deprecated (type);
              if (deptype)
-               warn_deprecated_use (deptype, NULL_TREE);
+               cp_warn_deprecated_use (deptype);
            }
 
          /* Top-level qualifiers on the parameters are
index 4cf2126608f0b7fedd008583bf5e09f395118a79..c2299baf52735e5683500f11e388fc3f35628d63 100644 (file)
@@ -5347,6 +5347,19 @@ cp_tree_code_length (enum tree_code code)
     }
 }
 
+/* Wrapper around warn_deprecated_use that doesn't warn for
+   current_class_type.  */
+
+void
+cp_warn_deprecated_use (tree node)
+{
+  if (TYPE_P (node)
+      && current_class_type
+      && TYPE_MAIN_VARIANT (node) == current_class_type)
+    return;
+  warn_deprecated_use (node, NULL_TREE);
+}
+
 /* Implement -Wzero_as_null_pointer_constant.  Return true if the
    conditions for the warning hold, false otherwise.  */
 bool
index 583c65d4d0a257a0cbcd61efe5c0ff8d1530c50c..2df51a543cffe61e924f48b63df297ffffe55bb0 100644 (file)
@@ -2057,7 +2057,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
       if (complain & tf_warning
          && TREE_DEPRECATED (type)
          && DECL_ARTIFICIAL (exp))
-       warn_deprecated_use (type, NULL_TREE);
+       cp_warn_deprecated_use (type);
     }
   else
     type = exp;
index 02ca79ffdedd6005cf6d6ff439c101fcc9ac9492..56d931727b582640202c4bd197dd8a0fe27fdc9c 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84222
+       * g++.dg/warn/deprecated.C (T::member3): Change dg-warning to dg-bogus.
+       * g++.dg/warn/deprecated-6.C (T::member3): Likewise.
+       * g++.dg/warn/deprecated-13.C: New test.
+
 2018-03-15  Olga Makhotina  <olga.makhotina@intel.com>
 
        * gcc.target/i386/sgx.c (_enclv_u32): Test new intrinsic.
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-13.C b/gcc/testsuite/g++.dg/warn/deprecated-13.C
new file mode 100644 (file)
index 0000000..ef05b95
--- /dev/null
@@ -0,0 +1,44 @@
+// PR c++/84222
+// { dg-do compile }
+
+struct __attribute__((deprecated)) C {         // { dg-message "declared here" }
+  C () {}
+  C (const C &);                               // { dg-bogus "'C' is deprecated" }
+  C (const C &x, const C &y) { C z = x; }      // { dg-bogus "'C' is deprecated" }
+  void foo (const C &x, const C &y);           // { dg-bogus "'C' is deprecated" }
+};
+
+void
+C::foo (const C &x, const C &y)                        // { dg-bogus "'C' is deprecated" }
+{
+  C z = x;                                     // { dg-bogus "'C' is deprecated" }
+}
+
+void
+bar (const C &x, const C &y)                   // { dg-warning "'C' is deprecated" }
+{
+  C z = x;                                     // { dg-warning "'C' is deprecated" }
+}
+
+template <int N>
+struct __attribute__((deprecated)) D {         // { dg-message "declared here" }
+  D () {}
+  D (const D &);                               // { dg-bogus "is deprecated" }
+  D (const D &x, const D &y) { D z = x; }      // { dg-bogus "is deprecated" }
+  void foo (const D &x, const D &y);           // { dg-bogus "is deprecated" }
+};
+
+template <int N>
+void
+D<N>::foo                                      // { dg-bogus "is deprecated" "" { xfail *-*-* } }
+(const D &x, const D &y)                       // { dg-bogus "is deprecated" }
+{
+  D z = x;                                     // { dg-bogus "is deprecated" }
+}
+
+template <int N>
+void
+bar (const D<N> &x, const D<N> &y)             // { dg-warning "is deprecated" }
+{
+  D<N> z = x;                                  // { dg-warning "is deprecated" }
+}
index a2c4b58033a0b8f07ca141991cd358ea460ba507..b3c390be3858e78367eb0246b5f285cda48a6e14 100644 (file)
@@ -98,7 +98,7 @@ T *p3;                                // { dg-warning "'T' is deprecated: Please avoid T" }
 
 inline void T::member1(int) {}
 
-int T::member3(T *p)           // { dg-warning "'T' is deprecated: Please avoid T" }
+int T::member3(T *p)           // { dg-bogus "'T' is deprecated: Please avoid T" }
 {
   p->member1(1);                       /* { dg-warning "'void T::member1\\(int\\)' is deprecated: Please avoid member1" } */
   (*p).member1(2);                     /* { dg-warning "'void T::member1\\(int\\)' is deprecated: Please avoid member1" } */
index 8b89a34a2dab52469a4ef64fcfa0ba197b8b62a3..c5ccbf3271fdde882f9a530e37743a667b750b5c 100644 (file)
@@ -102,7 +102,7 @@ T *p3;                              // { dg-warning "'T' is deprecated" }
 
 inline void T::member1(int) {}
 
-int T::member3(T *p)           // { dg-warning "'T' is deprecated" }
+int T::member3(T *p)           // { dg-bogus "'T' is deprecated" }
 {
   p->member1(1);                       /* { dg-warning "'void T::member1\\(int\\)' is deprecated" } */
   (*p).member1(2);                     /* { dg-warning "'void T::member1\\(int\\)' is deprecated" } */
@@ -113,5 +113,3 @@ int T::member3(T *p)                // { dg-warning "'T' is deprecated" }
   return f1();                                 /* { dg-warning "'INT1 f1\\(\\)' is deprecated" } */
 }
 #endif
-
-