This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/58777] New: Taking address of variant/union member is not always a constant expression


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]