This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58777] New: Taking address of variant/union member is not always a constant expression
- From: "lucdanton at free dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Oct 2013 05:00:46 +0000
- Subject: [Bug c++/58777] New: Taking address of variant/union member is not always a constant expression
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58777
Bug ID: 58777
Summary: Taking address of variant/union member is not always a
constant expression
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: lucdanton at free dot fr
$ g++-trunk --version
g++-trunk (GCC) 4.9.0 20131017 (experimental)
$ cat main.cpp
union foo { int i; double d; };
constexpr int const* addr(foo const& f)
{ return &f.i; }
constexpr int const& ref(foo const& f)
{ return f.i; }
int main()
{
constexpr foo f { 42 };
// Fine
static_assert( &f.i, "" );
// Not fine
static_assert( addr(f), "" );
// Not fine
static_assert( &ref(f), "" );
}
$ g++-trunk -std=c++11 -Wall main.cpp
main.cpp: In function 'int main()':
main.cpp:15:5: error: non-constant condition for static assertion
static_assert( addr(f), "" );
^
main.cpp:15:5: error: '& f.foo::i' is not a constant expression
main.cpp:17:5: error: non-constant condition for static assertion
static_assert( &ref(f), "" );
^
main.cpp:17:5: error: '& f.foo::i' is not a constant expression