From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 77798385840A; Mon, 24 Oct 2022 14:26:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77798385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666621605; bh=NEa2kag9kFbiPgdC27XZA8aBY5b4IvkF5V7/x0ANvyU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iQnhkPeuIZiYDZ0eZtN0fBmxlx6d6S+r6IWKja0FVw09kQoZWu5a/t1UCs1X38y7M LWo7PefzSuSpndHBMsKlk3VaKV0u6JvUPqOzEqxyfJnGruZys+agpMy6txNpgFiajD olKMWrOQnKg1Aln62WJTCUW8AmRA7Ezu6N1sqf5U= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105774] Bogus overflow in constant expression with signed char++ Date: Mon, 24 Oct 2022 14:26:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105774 --- Comment #6 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:da8c362c4c18cff2f2dfd5c4706bdda7576899a4 commit r13-3458-gda8c362c4c18cff2f2dfd5c4706bdda7576899a4 Author: Jakub Jelinek 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 gimplificati= on 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 =3D TREE_TYPE (TREE_OPERAND (*expr_p, 0)); if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type)) { if (!TYPE_OVERFLOW_WRAPS (type)) type =3D unsigned_type_for (type); return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, ty= pe); } 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 PR c++/105774 * constexpr.cc (cxx_eval_increment_expression): For signed types that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int ty= pe. * g++.dg/cpp1y/constexpr-105774.C: New test.=