[Bug c++/87506] [7/8/9 Regression] ICE with inherited constexpr constructor with const argument

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 16 18:27:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I wonder if adjust_temp_type really needs to adjust type from one variant to
another one (in this case the type of temp is A, but the type we want is const
A).
If it does for some reason, then perhaps adjust_temp_type could handle
EMPTY_CLASS_EXPR temp if TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT
(TREE_TYPE (temp)) ?
E.g. this fixes the testcase, but is just a shot in the dark:
--- gcc/cp/constexpr.c.jj       2018-11-16 10:22:18.668258171 +0100
+++ gcc/cp/constexpr.c  2018-11-16 19:24:13.564095334 +0100
@@ -1281,6 +1281,9 @@ adjust_temp_type (tree type, tree temp)
   /* Avoid wrapping an aggregate value in a NOP_EXPR.  */
   if (TREE_CODE (temp) == CONSTRUCTOR)
     return build_constructor (type, CONSTRUCTOR_ELTS (temp));
+  if (TREE_CODE (temp) == EMPTY_CLASS_EXPR
+      && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (temp)))
+    return build0 (EMPTY_CLASS_EXPR, type);
   gcc_assert (scalarish_type_p (type));
   return cp_fold_convert (type, temp);
 }


More information about the Gcc-bugs mailing list