[gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: Fix rejects-valid bug in cxx_eval_outermost_constant_expr [PR93905]

Jakub Jelinek jakub@gcc.gnu.org
Thu Sep 17 16:47:40 GMT 2020


https://gcc.gnu.org/g:752d1b9307c00b071b5f38be451261123cddefab

commit 752d1b9307c00b071b5f38be451261123cddefab
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 26 09:02:05 2020 +0100

    c++: Fix rejects-valid bug in cxx_eval_outermost_constant_expr [PR93905]
    
    The following testcase is rejected in 8.3, but was accepted in 8.2 and
    is in 9.x.  This started with my PR87934
            * constexpr.c (cxx_eval_constant_expression) <case CONSTRUCTOR>: Do
            re-process TREE_CONSTANT CONSTRUCTORs if they aren't reduced constant
            expressions.
    backport, where the NSDMI CONSTRUCTOR that contains CONST_DECLs is now
    constexpr evaluated so that it doesn't contain them.  The difference from
    9.x is that 9.x doesn't call get_target_expr if we got a CONSTRUCTOR for a
    class type for something that has been originally a CONSTRUCTOR too.
    
    This patch cherry-picks just that hunk of the r9-3835 change.
    
    2020-02-26  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/93905
            Backported from mainline
            2018-11-04  Jason Merrill  <jason@redhat.com>
    
            * constexpr.c (cxx_eval_outermost_constant_expr): Don't wrap a
            CONSTRUCTOR if one was passed in.
    
            * g++.dg/cpp0x/pr93905.C: New test.

Diff:
---
 gcc/cp/ChangeLog                     |  9 +++++++++
 gcc/cp/constexpr.c                   |  6 ++----
 gcc/testsuite/ChangeLog              |  5 +++++
 gcc/testsuite/g++.dg/cpp0x/pr93905.C | 18 ++++++++++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1b5e2bb2cde..40a1f39dfb0 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/93905
+	Backported from mainline
+	2018-11-04  Jason Merrill  <jason@redhat.com>
+
+	* constexpr.c (cxx_eval_outermost_constant_expr): Don't wrap a
+	CONSTRUCTOR if one was passed in.
+
 2020-02-26  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5fb0623ed58..bebe72e4db9 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4998,15 +4998,13 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
       if (TREE_CODE (t) == TARGET_EXPR
 	  && TARGET_EXPR_INITIAL (t) == r)
 	return t;
-      else
+      else if (TREE_CODE (t) != CONSTRUCTOR)
 	{
 	  r = get_target_expr (r);
 	  TREE_CONSTANT (r) = true;
-	  return r;
 	}
     }
-  else
-    return r;
+  return r;
 }
 
 /* Returns true if T is a valid subexpression of a constant expression,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index be5addaffd0..4a568fa338d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/93905
+	* g++.dg/cpp0x/pr93905.C: New test.
+
 2020-02-26  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr93905.C b/gcc/testsuite/g++.dg/cpp0x/pr93905.C
new file mode 100644
index 00000000000..81c6266a795
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr93905.C
@@ -0,0 +1,18 @@
+// PR c++/93905
+// { dg-do compile { target c++11 } }
+
+enum class E { VALUE };
+
+struct B {
+  E e{E::VALUE};
+protected:
+  ~B () = default;  
+};
+
+struct D : B {};
+
+int
+main ()
+{
+  D d{};
+}


More information about the Gcc-cvs mailing list