Bug 77539 - gcc-5/6: comparison of array to nullptr failure in constexpr (fixed by r235506 on trunk)
Summary: gcc-5/6: comparison of array to nullptr failure in constexpr (fixed by r23550...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.1
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-09-09 07:59 UTC by Markus Trippelsdorf
Modified: 2016-09-14 16:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.0
Known to fail: 5.4.0, 6.2.0
Last reconfirmed: 2016-09-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2016-09-09 07:59:56 UTC
In http://stackoverflow.com/questions/39405241/constexpr-comparision-to-nullptr-bug-or-feature/ a user posted the following testcase:

trippels@gcc2-power8 ~ % cat const2.ii
constexpr int foobar()
{
  int array[100] = {};
  int *ar = array;
  if (ar == nullptr) // Error...
  {
    return 0;
  }
  return 1;
}
static_assert(foobar(),"");

trippels@gcc2-power8 ~ % ~/gcc_6/usr/local/bin/g++ -c const2.ii
const2.ii:12:1: error: non-constant condition for static assertion
 static_assert(foobar(),"");
 ^~~~~~~~~~~~~
const2.ii:12:21:   in constexpr expansion of ‘foobar()’
const2.ii:5:10: error: ‘(((int*)(& array)) == 0u)’ is not a constant expression
   if (ar == nullptr) // Error...
       ~~~^~~~~~~~~~

This was fixed on trunk by r235506.

Nathan, would could you please backport your fix to gcc-6 branch?
Comment 1 Nathan Sidwell 2016-09-14 14:29:32 UTC
Author: nathan
Date: Wed Sep 14 14:29:01 2016
New Revision: 240136

URL: https://gcc.gnu.org/viewcvs?rev=240136&root=gcc&view=rev
Log:
	cp/
	PR c++/77539
	* constexpr.c (get_fundef_copy): Use the original function for
	non-recursive evaluations.
	(save_fundef_copy): Always expect a slot to be available.

	testsuite/
	PR c++/77539
	* g++.dg/cpp0x/constexpr-recursion3.C: New.
	* g++.dg/ubsan/pr63956.C: Adjust error location.
	* g++.dg/cpp1y/pr77539.C: New.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion3.C
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp1y/pr77539.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/constexpr.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
    branches/gcc-6-branch/gcc/testsuite/g++.dg/ubsan/pr63956.C
Comment 2 Nathan Sidwell 2016-09-14 16:14:24 UTC
Author: nathan
Date: Wed Sep 14 16:13:52 2016
New Revision: 240138

URL: https://gcc.gnu.org/viewcvs?rev=240138&root=gcc&view=rev
Log:
	PR c++/77539
	* g++.dg/cpp1y/pr77539.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/pr77539.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 3 Nathan Sidwell 2016-09-14 16:15:17 UTC
Patch backported, new testcase applied to trunk as well.