On 11/11/19 7:54 PM, Marek Polacek wrote:
Part of P1327R1 is to allow typeid with an operand of polymorphic type in
constexpr.  I found that we pretty much support it already, the only tweak
was to allow TYPEID_EXPR (only created in a template) in constexpr in C++20.

I also noticed this in build_typeid:
   /* FIXME when integrating with c_fully_fold, mark
      resolves_to_fixed_type_p case as a non-constant expression.  */
   if (TYPE_POLYMORPHIC_P (TREE_TYPE (exp))
       && ! resolves_to_fixed_type_p (exp, &nonnull)
       && ! nonnull)
but I'm not quite sure what to do with it.

Remove it, I think.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-11-11  Marek Polacek  <pola...@redhat.com>

        PR c++/88337 - P1327R1: Allow polymorphic typeid in constexpr.
        * constexpr.c (potential_constant_expression_1): Allow a typeid
        expression whose operand is of polymorphic type in constexpr in
        C++20.

        * g++.dg/cpp2a/constexpr-typeid1.C: New test.
        * g++.dg/cpp2a/constexpr-typeid2.C: New test.
        * g++.dg/cpp2a/constexpr-typeid3.C: New test.
        * g++.dg/cpp2a/constexpr-typeid4.C: New test.

diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 20fddc57825..430c65694b7 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -7018,11 +7018,13 @@ potential_constant_expression_1 (tree t, bool 
want_rval, bool strict, bool now,
        return false;
case TYPEID_EXPR:
-      /* -- a typeid expression whose operand is of polymorphic
-            class type;  */
+      /* In C++20, a typeid expression whose operand is of polymorphic
+        class type can be constexpr.  */
        {
          tree e = TREE_OPERAND (t, 0);
-        if (!TYPE_P (e) && !type_dependent_expression_p (e)
+       if (cxx_dialect < cxx2a

Do we want to allow this before C++20 if !strict?  OK either way.

Jason

Reply via email to