• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GCC with patches for OS216


Commit MetaInfo

Revision08c8c973c082457a7d6192673e87475f1fdfdbef (tree)
Zeit2020-01-15 05:20:12
AutorJason Merrill <jason@redh...>
CommiterJason Merrill

Log Message

PR c++/92590 - wrong handling of inherited default ctor.

I thought my earlier fix for 91930 was an obvious bug fix, but apparently an
inherited constructor does not count as user-declared. So this patch
reverts that change and the other follow-on patches, and fixes 91930
differently, by not letting the inherited default constructor hide the
implicitly-declared default constructor.

* class.c (add_method): A constrained inherited ctor doesn't hide an
implicit derived ctor.

Revert:
PR c++/91930 - ICE with constrained inherited default ctor.
* name-lookup.c (do_class_using_decl): Set TYPE_HAS_USER_CONSTRUCTOR
for inherited constructor.
PR c++/92552 - ICE with inherited constrained default ctor.
* pt.c (instantiate_class_template_1): Copy
TYPE_HAS_USER_CONSTRUCTOR.
PR c++/92594 - ICE with inherited trivial default ctor.
* method.c (trivial_fn_p): Treat an inherited default constructor
like a normal default constructor.

Ändern Zusammenfassung

Diff

--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -14,6 +14,20 @@
1414
1515 2020-01-14 Jason Merrill <jason@redhat.com>
1616
17+ PR c++/92590 - wrong handling of inherited default ctor.
18+ * class.c (add_method): A constrained inherited ctor doesn't hide an
19+ implicit derived ctor.
20+ Revert:
21+ PR c++/92552 - ICE with inherited constrained default ctor.
22+ * pt.c (instantiate_class_template_1): Copy
23+ TYPE_HAS_USER_CONSTRUCTOR.
24+ PR c++/91930 - ICE with constrained inherited default ctor.
25+ * name-lookup.c (do_class_using_decl): Set TYPE_HAS_USER_CONSTRUCTOR
26+ for inherited constructor.
27+ PR c++/92594 - ICE with inherited trivial default ctor.
28+ * method.c (trivial_fn_p): Treat an inherited default constructor
29+ like a normal default constructor.
30+
1731 PR c++/92594 - ICE with inherited trivial default ctor.
1832 * method.c (trivial_fn_p): Treat an inherited default constructor
1933 like a normal default constructor.
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -1079,9 +1079,10 @@ add_method (tree type, tree method, bool via_using)
10791079 {
10801080 special_function_kind sfk = special_memfn_p (method);
10811081
1082- if (sfk == sfk_none)
1082+ if (sfk == sfk_none || DECL_INHERITED_CTOR (fn))
10831083 /* Non-special member functions coexist if they are not
1084- equivalently constrained. */
1084+ equivalently constrained. A member function is not hidden
1085+ by an inherited constructor. */
10851086 continue;
10861087
10871088 /* P0848: For special member functions, deleted, unsatisfied, or
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -458,12 +458,7 @@ trivial_fn_p (tree fn)
458458 /* If fn is a clone, get the primary variant. */
459459 if (tree prim = DECL_CLONED_FUNCTION (fn))
460460 fn = prim;
461- special_function_kind sfk = special_function_p (fn);
462- /* An inherited default constructor is equivalent to a non-inherited default
463- constructor, so let it be trivial. */
464- if (sfk == sfk_inheriting_constructor && default_ctor_p (fn))
465- sfk = sfk_constructor;
466- return type_has_trivial_fn (DECL_CONTEXT (fn), sfk);
461+ return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
467462 }
468463
469464 /* PARM is a PARM_DECL for a function which we want to forward to another
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -4634,7 +4634,6 @@ lookup_using_decl (tree scope, name_lookup &lookup)
46344634 maybe_warn_cpp0x (CPP0X_INHERITING_CTORS);
46354635 lookup.name = ctor_identifier;
46364636 CLASSTYPE_NON_AGGREGATE (current) = true;
4637- TYPE_HAS_USER_CONSTRUCTOR (current) = true;
46384637 }
46394638
46404639 /* Cannot introduce a constructor name. */
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11578,7 +11578,6 @@ instantiate_class_template_1 (tree type)
1157811578 SET_TYPE_ALIGN (type, TYPE_ALIGN (pattern));
1157911579 TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (pattern);
1158011580 CLASSTYPE_NON_AGGREGATE (type) = CLASSTYPE_NON_AGGREGATE (pattern);
11581- TYPE_HAS_USER_CONSTRUCTOR (type) = TYPE_HAS_USER_CONSTRUCTOR (pattern);
1158211581 if (ANON_AGGR_TYPE_P (pattern))
1158311582 SET_ANON_AGGR_TYPE_P (type);
1158411583 if (CLASSTYPE_VISIBILITY_SPECIFIED (pattern))
--- a/gcc/testsuite/g++.dg/concepts/inherit-ctor3.C
+++ b/gcc/testsuite/g++.dg/concepts/inherit-ctor3.C
@@ -11,7 +11,7 @@ template<typename T>
1111 };
1212
1313 template<typename T>
14- struct S2 : S1<T> {
14+ struct S2 : S1<T> { // { dg-error "no matching function" }
1515 using S1<T>::S1; // { dg-error "no matching function" }
1616 };
1717
@@ -19,5 +19,5 @@ struct X { } x;
1919
2020 int main() {
2121 S2<X> s1(0); // { dg-error "use of deleted function" }
22- S2<X> s2; // { dg-error "no matching function" }
22+ S2<X> s2; // { dg-error "use of deleted function" }
2323 }
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor35.C
@@ -0,0 +1,14 @@
1+// PR c++/92590
2+// { dg-do compile { target c++11 } }
3+
4+class Base {
5+ protected:
6+ Base();
7+};
8+
9+class Derived : public Base {
10+ public:
11+ using Base::Base;
12+};
13+
14+Derived d;
--- a/gcc/testsuite/g++.dg/cpp0x/inh-ctor5.C
+++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor5.C
@@ -6,13 +6,13 @@ struct B1 {
66 struct B2 {
77 B2(double) { }
88 };
9-struct D1 : B1 {
9+struct D1 : B1 { // { dg-error "no match" }
1010 using B1::B1; // implicitly declares D1(int)
1111 int x;
1212 };
1313 void test() {
1414 D1 d(6); // OK: d.x is not initialized
15- D1 e; // { dg-error "no match" } D1 has no default constructor
15+ D1 e; // { dg-error "deleted" } D1 has no default constructor
1616 }
1717 struct D2 : B2 {
1818 using B2::B2; // { dg-error "B1::B1" }
--- a/gcc/testsuite/g++.dg/cpp1z/inh-ctor22.C
+++ b/gcc/testsuite/g++.dg/cpp1z/inh-ctor22.C
@@ -12,7 +12,7 @@ struct B2 {
1212
1313 int get();
1414
15-struct D1 : B1 {
15+struct D1 : B1 { // { dg-message "B1::B1" }
1616 using B1::B1; // inherits B1(int, ...)
1717 int x;
1818 int y = get();
@@ -22,7 +22,7 @@ void test() {
2222 D1 d(2, 3, 4); // OK: B1 is initialized by calling B1(2, 3, 4),
2323 // then d.x is default-initialized (no initialization is performed),
2424 // then d.y is initialized by calling get()
25- D1 e; // { dg-error "" } D1 has no default constructor
25+ D1 e; // { dg-error "" } D1 has a deleted default constructor
2626 }
2727
2828 struct D2 : B2 {
--- a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor2.C
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor2.C
@@ -9,10 +9,10 @@ template<typename T>
99 };
1010
1111 template<typename T>
12- struct S2 : S1<T> {
12+ struct S2 : S1<T> { // { dg-error "matching" }
1313 using S1<T>::S1;
1414 };
1515
1616 int main() {
17- S2<int> s; // { dg-error "no matching function" }
17+ S2<int> s; // { dg-error "deleted function" }
1818 }
--- a/gcc/testsuite/g++.dg/template/crash7.C
+++ b/gcc/testsuite/g++.dg/template/crash7.C
@@ -10,4 +10,6 @@ template <typename> struct A
1010 template <typename> A(typename A::X) {} // { dg-error "incomplete" }
1111 };
1212
13-A<void> a; // { dg-message "no match" }
13+// We currently don't give the "no match" error because we don't add the
14+// invalid constructor template to TYPE_METHODS.
15+A<void> a; // { dg-message "required" }
--- a/gcc/testsuite/g++.old-deja/g++.pt/error2.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/error2.C
@@ -9,7 +9,7 @@ public:
99
1010 void f ()
1111 {
12- Test<void> c; // { dg-error "no match" }
12+ Test<void> c; // { dg-message "required" }
1313 }
1414
1515