]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Don't synthesize sfk_comparison method multiple times [PR94907]
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 May 2020 21:36:31 +0000 (23:36 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 7 May 2020 13:20:26 +0000 (15:20 +0200)
On the following testcase we ICE, because synthesize_method is called twice
on the same sfk_comparison method fndecl, the first time it works fine
because start_preparsed_function in that case sets both
current_function_decl and cfun, but second time it is called it only sets
the former and keeps cfun NULL, so we ICE when trying to store
current_function_returns_value.
I think it is just wrong to call synthesize_method multiple times, and most
synthesize_method callers avoid that by not calling it if DECL_INITIAL is
already set, so this patch does that too.

2020-05-06  Jakub Jelinek  <jakub@redhat.com>

PR c++/94907
* method.c (defaulted_late_check): Don't call synthesize_method
on constexpr sfk_comparison if it has been called on it already.

* g++.dg/cpp2a/spaceship-synth8.C: New test.

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/spaceship-synth8.C [new file with mode: 0644]

index e99485b12db468aca4ef0cba5978718ea9cab797..f32ef9239c7b6793aa83da6c7d316fb3c1162e4d 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/94907
+       * method.c (defaulted_late_check): Don't call synthesize_method
+       on constexpr sfk_comparison if it has been called on it already.
+
 2020-05-07  Release Manager
 
        * GCC 10.1.0 released.
index fb2dd47013f4f7f15e38dec8aa03b703c2460f99..47f96aa845ec357ef0ddf168f8ea15072d57e1e1 100644 (file)
@@ -2939,7 +2939,7 @@ defaulted_late_check (tree fn)
     {
       /* If the function was declared constexpr, check that the definition
         qualifies.  Otherwise we can define the function lazily.  */
-      if (DECL_DECLARED_CONSTEXPR_P (fn))
+      if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn))
        synthesize_method (fn);
       return;
     }
index 0bc4058d318fd4beb061c052e9f534daa9b85d6d..28faf7a9b563a561efb5413cb2f53dcb1c9e9d46 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/94907
+       * g++.dg/cpp2a/spaceship-synth8.C: New test.
+
 2020-05-06  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/94873
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth8.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth8.C
new file mode 100644 (file)
index 0000000..d0d68c7
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/94907
+// { dg-do compile { target c++2a } }
+
+namespace std { struct strong_ordering { }; }
+
+struct E;
+struct D {
+  virtual std::strong_ordering operator<=>(const struct E&) const = 0;
+};
+struct E : D {
+  std::strong_ordering operator<=>(const E&) const override = default;
+};