Bug 60430 - static_assert and reference to const/constexpr
Summary: static_assert and reference to const/constexpr
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 70247 (view as bug list)
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2014-03-05 16:08 UTC by Florent Hivert
Modified: 2017-05-12 17:55 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.2, 4.9.1, 5.3.0, 6.0
Last reconfirmed: 2014-08-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florent Hivert 2014-03-05 16:08:09 UTC
I think the following should be accepted:


constexpr const int A = 42;
const int &B = A;
static_assert(&A == &B, "Bug");

int main() {return 0;}


Indeed, even if B is not constexpr its address is. On the contrary GCC complains with


bug2.cpp:3:1: error: non-constant condition for static assertion
 static_assert(&A == &B, "Bug");
 ^
bug2.cpp:3:1: error: the value of ‘B’ is not usable in a constant expression
bug2.cpp:2:12: note: ‘B’ was not declared ‘constexpr’
 const int &B = A;
Comment 1 Florent Hivert 2014-05-28 10:04:08 UTC
The problem remains with the newly released GCC 4.9.0. I've upgraded the tag.
Comment 2 Jonathan Wakely 2014-05-28 13:47:36 UTC
THere's no need to update the version - if the bug is still open t hat means it's still a bug in later versions, and by changing it you've lost the information that the bug is present in 4.8
Comment 3 Martin Sebor 2016-03-16 02:20:20 UTC
*** Bug 70247 has been marked as a duplicate of this bug. ***
Comment 4 Martin Sebor 2016-03-16 02:23:03 UTC
As shown in the duplicate bug 70247 the top of the trunk of 6.0 still rejects this code.
Comment 5 Paolo Carlini 2017-05-12 17:13:59 UTC
This is fixed in 7.1.0. I'm adding the testcase and closing the bug.
Comment 6 paolo@gcc.gnu.org 2017-05-12 17:54:25 UTC
Author: paolo
Date: Fri May 12 17:53:54 2017
New Revision: 247986

URL: https://gcc.gnu.org/viewcvs?rev=247986&root=gcc&view=rev
Log:
2017-05-12  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/60430
	* g++.dg/cpp0x/pr60430.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr60430.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 7 Paolo Carlini 2017-05-12 17:55:00 UTC
Done.