[Bug c++/67371] Never executed "throw" in constexpr function fails to compile

matthijsvanduin at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jul 21 06:08:00 GMT 2017


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

Matthijs van Duin <matthijsvanduin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matthijsvanduin at gmail dot com

--- Comment #13 from Matthijs van Duin <matthijsvanduin at gmail dot com> ---
This is still not working for me in g++ 6 and 7:

constexpr void foo( bool ok ) {
        if( ok )
                return;
        throw;
}

In function ‘constexpr void foo(bool)’:
error: expression ‘<throw-expression>’ is not a constant-expression


Rewriting the code as:

constexpr void foo( bool ok ) {
        if( ok )
                return;
        else
                throw;
}

gets rid of the error, but this can be really awkward to do in more complicated
functions.


More information about the Gcc-bugs mailing list