From 4a5a49b034eed5373f6968c99bda1827f1479580 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 15 Mar 2018 18:45:01 +0100 Subject: [PATCH] re PR c++/84222 ([[deprecated]] class complains about internal class usage) 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 | 10 ++++++ gcc/cp/cp-tree.h | 1 + gcc/cp/decl.c | 20 ++++++++--- gcc/cp/tree.c | 13 +++++++ gcc/cp/typeck2.c | 2 +- gcc/testsuite/ChangeLog | 7 ++++ gcc/testsuite/g++.dg/warn/deprecated-13.C | 44 +++++++++++++++++++++++ gcc/testsuite/g++.dg/warn/deprecated-6.C | 2 +- gcc/testsuite/g++.dg/warn/deprecated.C | 4 +-- 9 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/deprecated-13.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dc7708ba499..a4f845a061b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2018-03-15 Jakub Jelinek + + 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 PR c++/84820 - no error for invalid qualified-id. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 186a37eea6b..99c51a89092 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 45daccda916..98f762e5253 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 4cf2126608f..c2299baf527 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -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 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 583c65d4d0a..2df51a543cf 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 02ca79ffded..56d931727b5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-03-15 Jakub Jelinek + + 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 * 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 index 00000000000..ef05b95f026 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-13.C @@ -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 +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 +void +D::foo // { dg-bogus "is deprecated" "" { xfail *-*-* } } +(const D &x, const D &y) // { dg-bogus "is deprecated" } +{ + D z = x; // { dg-bogus "is deprecated" } +} + +template +void +bar (const D &x, const D &y) // { dg-warning "is deprecated" } +{ + D z = x; // { dg-warning "is deprecated" } +} diff --git a/gcc/testsuite/g++.dg/warn/deprecated-6.C b/gcc/testsuite/g++.dg/warn/deprecated-6.C index a2c4b58033a..b3c390be385 100644 --- a/gcc/testsuite/g++.dg/warn/deprecated-6.C +++ b/gcc/testsuite/g++.dg/warn/deprecated-6.C @@ -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" } */ diff --git a/gcc/testsuite/g++.dg/warn/deprecated.C b/gcc/testsuite/g++.dg/warn/deprecated.C index 8b89a34a2da..c5ccbf3271f 100644 --- a/gcc/testsuite/g++.dg/warn/deprecated.C +++ b/gcc/testsuite/g++.dg/warn/deprecated.C @@ -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 - - -- 2.30.2