[Bug c++/96182] GCC accepts constexpr function with no return-statement

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 31 21:08:52 GMT 2020


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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5f9669d9e23a1116e040c80e0f3d4f43639bda52

commit r11-2473-g5f9669d9e23a1116e040c80e0f3d4f43639bda52
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 31 23:08:00 2020 +0200

    c++: Use error_at rather than warning_at for missing return in constexpr
functions [PR96182]

    For C++11 we already emit an error if a constexpr function doesn't contain
    a return statement, because in C++11 that is the only thing it needs to
    contain, but for C++14 we would normally issue a -Wreturn-type warning.

    As mentioned by Jonathan, such constexpr functions are invalid, no
    diagnostics required, because there doesn't exist any arguments for
    which it would result in valid constant expression.

    This raises it to an error in such cases.  The !LAMBDA_TYPE_P case
    is to avoid error on g++.dg/pr81194.C where the user didn't write
    constexpr anywhere and the operator() is compiler generated.

    2020-07-31  Jakub Jelinek  <jakub@redhat.com>

            PR c++/96182
            * decl.c (finish_function): In constexpr functions use for C++14
and
            later error instead of warning if no return statement is present
and
            diagnose it regardless of warn_return_type.  Move the
warn_return_type
            diagnostics earlier in the function.

            * g++.dg/cpp1y/constexpr-96182.C: New test.
            * g++.dg/other/error35.C (S<T>::g()): Add return statement.
            * g++.dg/cpp1y/pr63996.C (foo): Likewise.
            * g++.dg/cpp1y/constexpr-return2.C (f): Likewise.
            * g++.dg/cpp1y/var-templ44.C (make_array): Add throw 1.


More information about the Gcc-bugs mailing list