On 3/25/20 3:29 PM, Jakub Jelinek wrote:
Hi!

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 defaulted or deleted.

A template can't be defaulted, but indeed it can be deleted.

So far tested with check-c++-all and check-libstdc++-v3, ok for trunk if it
passes full bootstrap/regtest?

OK.

2020-03-25  Jakub Jelinek  <ja...@redhat.com>

        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/class.c.jj   2020-03-09 21:03:42.345824043 +0100
+++ gcc/cp/class.c      2020-03-25 19:30:27.920029264 +0100
@@ -5159,12 +5159,10 @@ in_class_defaulted_default_constructor (
  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. */
--- gcc/testsuite/g++.dg/cpp1z/pr81349.C.jj     2020-03-25 19:40:16.136248587 
+0100
+++ gcc/testsuite/g++.dg/cpp1z/pr81349.C        2020-03-25 19:40:37.016936883 
+0100
@@ -0,0 +1,29 @@
+// PR c++/81349
+// { dg-do compile { target c++17_only } }
+
+#include <type_traits>
+
+struct A {
+  A (int) = delete;
+};
+
+struct B {
+  template <typename T>
+  B (T) = delete;
+};
+
+template <typename U>
+struct C {
+  C (U) = delete;
+};
+
+template <typename U>
+struct D {
+  template <typename T>
+  D (T, U) = delete;
+};
+
+static_assert (std::is_aggregate_v<A>);
+static_assert (std::is_aggregate_v<B>);
+static_assert (std::is_aggregate_v<C<int>>);
+static_assert (std::is_aggregate_v<D<int>>);

        Jakub


Reply via email to