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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Actually, I think it is a bug in convert_nontype_argument.
For reflections it does
  else if (REFLECTION_TYPE_P (type))
    {
      if (!REFLECTION_TYPE_P (TREE_TYPE (expr)))
        {
          if (complain & tf_error)
            error ("%qE is not a valid template argument for type %qT "
                   "because it is of type %qT", expr, type, TREE_TYPE (expr));
          return NULL_TREE;
        }
      return expr;
    }
while e.g. for scalars it does:
      /* Notice that there are constant expressions like '4 % 0' which
         do not fold into integer constants.  */
      if (!CONSTANT_CLASS_P (expr) && !val_dep_p)
        {
          if (complain & tf_error)
            {
              int errs = errorcount, warns = warningcount + werrorcount;
              if (!require_potential_constant_expression (expr))
                expr = error_mark_node;
              else
                expr = cxx_constant_value (expr);
...
            }
          else
            return NULL_TREE;
       }
So bet for reflections it should also do something similar, if !val_dep_p and
expr is not REFLECT_EXPR, return NULL_TREE or use cxx_constant_value.

And I wonder if the same problem isn't in the nullptr_t case, there we have
  else if (NULLPTR_TYPE_P (type))
    {
      if (!NULLPTR_TYPE_P (TREE_TYPE (expr)))
        {
          if (complain & tf_error)
            error ("%qE is not a valid template argument for type %qT "
                   "because it is of type %qT", expr, type, TREE_TYPE (expr));
          return NULL_TREE;
        }
      return expr;
    }
and nothing that would similarly check for integer_zerop (expr).

Reply via email to