From dab932d1519ba07fb4c49e6849ee7ceb02c0d603 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 26 Mar 2020 09:31:15 +0100 Subject: [PATCH] c++: Fix up user_provided_p [PR81349] The standard says: "A function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration." I don't see anything about function templates having different rules here, but user_provided_p does return true for all TEMPLATE_DECLs. The following patch fixes it by treating as user-provided only templates that aren't deleted. 2020-03-26 Jakub Jelinek PR c++/81349 * class.c (user_provided_p): Use STRIP_TEMPLATE instead of returning true for all TEMPLATE_DECLs. * g++.dg/cpp1z/pr81349.C: New test. --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/class.c | 10 ++++------ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp1z/pr81349.C | 29 ++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/pr81349.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9ff2525f83d..af8f49bd031 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2020-03-26 Jakub Jelinek + PR c++/81349 + * class.c (user_provided_p): Use STRIP_TEMPLATE instead of returning + true for all TEMPLATE_DECLs. + PR c++/94272 * cp-gimplify.c (cp_genericize_r): Handle STATEMENT_LIST. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 5340799fdd3..41f52e5a5a0 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5159,12 +5159,10 @@ in_class_defaulted_default_constructor (tree t) bool user_provided_p (tree fn) { - if (TREE_CODE (fn) == TEMPLATE_DECL) - return true; - else - return (!DECL_ARTIFICIAL (fn) - && !(DECL_INITIALIZED_IN_CLASS_P (fn) - && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn)))); + fn = STRIP_TEMPLATE (fn); + return (!DECL_ARTIFICIAL (fn) + && !(DECL_INITIALIZED_IN_CLASS_P (fn) + && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn)))); } /* Returns true iff class T has a user-provided constructor. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d5c12f20a3..6091bcc1f05 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2020-03-26 Jakub Jelinek + PR c++/81349 + * g++.dg/cpp1z/pr81349.C: New test. + PR c++/94272 * g++.dg/debug/pr94272.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/pr81349.C b/gcc/testsuite/g++.dg/cpp1z/pr81349.C new file mode 100644 index 00000000000..5195d190eb5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/pr81349.C @@ -0,0 +1,29 @@ +// PR c++/81349 +// { dg-do compile { target c++17_only } } + +#include + +struct A { + A (int) = delete; +}; + +struct B { + template + B (T) = delete; +}; + +template +struct C { + C (U) = delete; +}; + +template +struct D { + template + D (T, U) = delete; +}; + +static_assert (std::is_aggregate_v); +static_assert (std::is_aggregate_v); +static_assert (std::is_aggregate_v>); +static_assert (std::is_aggregate_v>); -- 2.30.2