]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Support C++20 virtual consteval functions. [PR88335]
authorJason Merrill <jason@redhat.com>
Thu, 25 Jun 2020 00:46:09 +0000 (20:46 -0400)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Mon, 17 Aug 2020 16:15:55 +0000 (13:15 -0300)
commit7c5693cecbf33249538b4edeecadf810c3b371b2
treeac05b6857a926a363f6d6c68f869f50555d59aa8
parent3a016ee4f208c0f8c864879f2e217302f092b5a9
c++: Support C++20 virtual consteval functions. [PR88335]

Jakub's partial implementation of consteval virtual had trouble with the
current ABI requirement that we omit the vtable slot for a consteval virtual
function; it's difficult to use the normal code for constant evaluation and
also magically make the slots disappear if the vtables get written out.  I
notice that Clang trunk also doesn't implement that requirement, and it
seems unnecessary to me; I expect consteval virtual functions to be
extremely rare, so it should be fine to just give them a vtable slot as
normal but put zero in it if the vtable gets emitted.  I've commented as
much to the ABI committee.

One of Jakub's testcases points out that we weren't handling thunks in
our constexpr virtual handling; that is fixed here as well.

Incidentally, being able to use C++11 range-for definitely simplified
clear_consteval_vfns.

gcc/c-family/ChangeLog:

* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_consteval.

gcc/cp/ChangeLog:

* decl.c (grokfndecl): Allow consteval virtual.
* search.c (check_final_overrider): Check consteval mismatch.
* constexpr.c (cxx_eval_thunk_call): New.
(cxx_eval_call_expression): Call it.
* cvt.c (cp_get_fndecl_from_callee): Handle FDESC_EXPR.
* decl2.c (mark_vtable_entries): Track vtables with consteval.
(maybe_emit_vtables): Pass consteval_vtables through.
(clear_consteval_vfns): Replace consteval with nullptr.
(c_parse_final_cleanups): Call it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval-virtual1.C: New test.
* g++.dg/cpp2a/consteval-virtual2.C: New test.
* g++.dg/cpp2a/consteval-virtual3.C: New test.
* g++.dg/cpp2a/consteval-virtual4.C: New test.
* g++.dg/cpp2a/consteval-virtual5.C: New test.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
gcc/c-family/c-cppbuiltin.c
gcc/cp/constexpr.c
gcc/cp/cvt.c
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/search.c
gcc/testsuite/g++.dg/cpp2a/consteval-virtual1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/consteval-virtual2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/consteval-virtual3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/consteval-virtual4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/consteval-virtual5.C [new file with mode: 0644]