Bug 69631 - [6 Regression] Bogus overflow in constant expression error
Summary: [6 Regression] Bogus overflow in constant expression error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P1 normal
Target Milestone: 6.0
Assignee: Jason Merrill
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2016-02-02 16:19 UTC by Marek Polacek
Modified: 2016-08-06 05:06 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-02-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2016-02-02 16:19:37 UTC
Starting with the C++ delayed folding merge, we reject this test with -fwrapv:

struct C {
  static const unsigned short max = static_cast<unsigned short>((32767 * 2 + 1));
};

q.C:2:80: error: overflow in constant expression [-fpermissive]
   static const unsigned short max = static_cast<unsigned short>((32767 * 2 + 1));
                                                                                ^
q.C:2:80: error: overflow in constant expression [-fpermissive]
q.C:2:80: error: overflow in constant expression [-fpermissive]
q.C:2:80: error: overflow in constant expression [-fpermissive]
Comment 1 Jason Merrill 2016-02-08 15:32:19 UTC
Author: jason
Date: Mon Feb  8 15:31:47 2016
New Revision: 233216

URL: https://gcc.gnu.org/viewcvs?rev=233216&root=gcc&view=rev
Log:
	PR c++/69631

gcc/
	* convert.c (convert_to_integer_1): Check dofold on truncation
	distribution.
	(convert_to_pointer_maybe_fold, convert_to_real_maybe_fold)
	(convert_to_integer_maybe_fold, convert_to_complex_maybe_fold):
	Rename from *_nofold.
	* convert.h (convert_to_pointer_nofold, convert_to_integer_nofold)
	(convert_to_real_nofold, convert_to_complex_nofold): New inlines.
gcc/cp/
	* cp-tree.h (CONV_FOLD, CONV_BACKEND_CONVERT): New.
	* cvt.c (convert): Pass CONV_BACKEND_CONVERT.
	(ocp_convert): Use *_maybe_fold.
	(cp_convert_to_pointer): Add dofold parameter.
	* cp-gimplify.c (cp_fold) [CONVERT_EXPR]: Call convert.

Added:
    trunk/gcc/testsuite/g++.dg/delayedfold/fwrapv1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/convert.c
    trunk/gcc/convert.h
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/cvt.c
Comment 2 Jason Merrill 2016-02-08 18:39:45 UTC
Fixed.