backport: re PR c++/84222 ([[deprecated]] class complains about internal class usage)

Backported from mainline
	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.

	* 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: r261924
This commit is contained in:
Jakub Jelinek 2018-06-22 22:43:09 +02:00 committed by Jakub Jelinek
parent 42e4700c95
commit 14203e0390
9 changed files with 91 additions and 10 deletions

View File

@ -1,6 +1,16 @@
2018-06-22 Jakub Jelinek <jakub@redhat.com> 2018-06-22 Jakub Jelinek <jakub@redhat.com>
Backported from mainline Backported from mainline
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-09 Jason Merrill <jason@redhat.com> 2018-03-09 Jason Merrill <jason@redhat.com>
Jakub Jelinek <jakub@redhat.com> Jakub Jelinek <jakub@redhat.com>

View File

@ -6708,6 +6708,7 @@ extern tree cxx_copy_lang_qualifiers (const_tree, const_tree);
extern void cxx_print_statistics (void); extern void cxx_print_statistics (void);
extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t); extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t);
extern void cp_warn_deprecated_use (tree);
/* in ptree.c */ /* in ptree.c */
extern void cxx_print_xnode (FILE *, tree, int); extern void cxx_print_xnode (FILE *, tree, int);

View File

@ -10400,7 +10400,7 @@ grokdeclarator (const cp_declarator *declarator,
suppress reports of deprecated items. */ suppress reports of deprecated items. */
if (type && TREE_DEPRECATED (type) if (type && TREE_DEPRECATED (type)
&& deprecated_state != DEPRECATED_SUPPRESS) && deprecated_state != DEPRECATED_SUPPRESS)
warn_deprecated_use (type, NULL_TREE); cp_warn_deprecated_use (type);
if (type && TREE_CODE (type) == TYPE_DECL) if (type && TREE_CODE (type) == TYPE_DECL)
{ {
typedef_decl = type; typedef_decl = type;
@ -10408,7 +10408,7 @@ grokdeclarator (const cp_declarator *declarator,
if (TREE_DEPRECATED (type) if (TREE_DEPRECATED (type)
&& DECL_ARTIFICIAL (typedef_decl) && DECL_ARTIFICIAL (typedef_decl)
&& deprecated_state != DEPRECATED_SUPPRESS) && 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 /* No type at all: default to `int', and set DEFAULTED_INT
because it was not a user-defined typedef. */ because it was not a user-defined typedef. */
@ -11203,8 +11203,18 @@ grokdeclarator (const cp_declarator *declarator,
explicitp = 2; explicitp = 2;
} }
arg_types = grokparms (declarator->u.function.parameters, tree pushed_scope = NULL_TREE;
&parms); 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 if (inner_declarator
&& inner_declarator->kind == cdk_id && inner_declarator->kind == cdk_id
@ -12721,7 +12731,7 @@ grokparms (tree parmlist, tree *parms)
{ {
tree deptype = type_is_deprecated (type); tree deptype = type_is_deprecated (type);
if (deptype) if (deptype)
warn_deprecated_use (deptype, NULL_TREE); cp_warn_deprecated_use (deptype);
} }
/* Top-level qualifiers on the parameters are /* Top-level qualifiers on the parameters are

View File

@ -4900,6 +4900,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 /* Implement -Wzero_as_null_pointer_constant. Return true if the
conditions for the warning hold, false otherwise. */ conditions for the warning hold, false otherwise. */
bool bool

View File

@ -1957,7 +1957,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
if (complain & tf_warning if (complain & tf_warning
&& TREE_DEPRECATED (type) && TREE_DEPRECATED (type)
&& DECL_ARTIFICIAL (exp)) && DECL_ARTIFICIAL (exp))
warn_deprecated_use (type, NULL_TREE); cp_warn_deprecated_use (type);
} }
else else
type = exp; type = exp;

View File

@ -3,6 +3,11 @@
Backported from mainline Backported from mainline
2018-03-15 Jakub Jelinek <jakub@redhat.com> 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.
PR target/84860 PR target/84860
* gcc.c-torture/compile/pr84860.c: New test. * gcc.c-torture/compile/pr84860.c: New test.

View File

@ -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" }
}

View File

@ -98,7 +98,7 @@ T *p3; // { dg-warning "'T' is deprecated: Please avoid T" }
inline void T::member1(int) {} 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(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" "" } */ (*p).member1(2); /* { dg-warning "'void T::member1\\(int\\)' is deprecated: Please avoid member1" "" } */

View File

@ -102,7 +102,7 @@ T *p3; // { dg-warning "'T' is deprecated" }
inline void T::member1(int) {} 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(1); /* { dg-warning "'void T::member1\\(int\\)' is deprecated" "" } */
(*p).member1(2); /* { 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" "" } */ return f1(); /* { dg-warning "'INT1 f1\\(\\)' is deprecated" "" } */
} }
#endif #endif