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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:20ef7d7c578dab0585d70fbea571a74e8e8d4b47

commit r12-8888-g20ef7d7c578dab0585d70fbea571a74e8e8d4b47
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Oct 24 16:25:29 2022 +0200

    c++: Fix up constexpr handling of char/signed char/short pre/post
inc/decrement [PR105774]

    signed char, char or short int pre/post inc/decrement are represented by
    normal {PRE,POST}_{INC,DEC}REMENT_EXPRs in the FE and only gimplification
    ensures that the {PLUS,MINUS}_EXPR is done in unsigned version of those
    types:
        case PREINCREMENT_EXPR:
        case PREDECREMENT_EXPR:
        case POSTINCREMENT_EXPR:
        case POSTDECREMENT_EXPR:
          {
            tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
            if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type))
              {
                if (!TYPE_OVERFLOW_WRAPS (type))
                  type = unsigned_type_for (type);
                return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type);
              }
            break;
          }
    This means during constant evaluation we need to do it similarly (either
    using unsigned_type_for or using widening to integer_type_node).
    The following patch does the latter.

    2022-10-24  Jakub Jelinek  <ja...@redhat.com>

            PR c++/105774
            * constexpr.cc (cxx_eval_increment_expression): For signed types
            that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int type.

            * g++.dg/cpp1y/constexpr-105774.C: New test.

    (cherry picked from commit da8c362c4c18cff2f2dfd5c4706bdda7576899a4)
  • [Bug c++/105774] Bogus overflow... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to