public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65985] New: compiler segfault with assert() in constexpr constructor body
@ 2015-05-02 20:15 rhalbersma at gmail dot com
  2015-05-02 20:19 ` [Bug c++/65985] " rhalbersma at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: rhalbersma at gmail dot com @ 2015-05-02 20:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65985

            Bug ID: 65985
           Summary: compiler segfault with assert() in constexpr
                    constructor body
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rhalbersma at gmail dot com
  Target Milestone: ---

The following code segfaults with -std=c++1y for g++ 5.1.0 and trunk 20150502
on the combination of constexpr and assert() in the constructor body (removing
either the constexpr keyword everywhere or the assert() will compile cleanly).  

#include <cassert>

class Angle
{
        int degrees = 0;

        constexpr auto invariant() const noexcept
        {
                return 0 <= degrees && degrees < 360;
        }

public:
        explicit constexpr Angle(int n) noexcept
        :
                degrees{n % 360}
        {
                assert(invariant());
        }

        /* implicit */ constexpr operator auto() const noexcept
        {
                return degrees;
        }          
};

int main() 
{
        static_assert(Angle{360} == 0, "");
}

This code correctly compiles with -std=c++14 from Clang 3.3 and higher.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-04 11:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-02 20:15 [Bug c++/65985] New: compiler segfault with assert() in constexpr constructor body rhalbersma at gmail dot com
2015-05-02 20:19 ` [Bug c++/65985] " rhalbersma at gmail dot com
2015-05-04 10:36 ` [Bug c++/65985] [5/6 Regression] " mpolacek at gcc dot gnu.org
2015-05-04 10:46 ` mpolacek at gcc dot gnu.org
2015-05-04 11:28 ` daniel.kruegler at googlemail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).