c++: Allow subobject references in C++20.
authorJason Merrill <jason@redhat.com>
Tue, 7 Jul 2020 05:41:35 +0000 (01:41 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 20 Jul 2020 21:54:18 +0000 (17:54 -0400)
commit812798917c59e95405a71b31ab37bd78c0f43f79
tree7819648c4081fc5e37fba3b3ae505472d5023bd0
parentd0ffe9d5dc83092e6de996483c4c08b439a316c0
c++: Allow subobject references in C++20.

The last new thing allowed by P1907R1: subobject addresses as template
arguments.  The ABI group has discussed mangling for this; there has been
some talk of a compressed subobject mangling, but it hasn't been finalized,
so for now I'm using normal expression mangling.  In order for two array
subobject references to compare as equal template arguments, the offsets
need to have the same type, so I convert them to always be the same type,
currently ptrdiff_t.  Base class conversions are represented as a cast to
reference type, only if necessary to resolve an ambiguity.

This patch also updates the value of __cpp_nontype_template_args, since
the paper is fully implemented.

gcc/cp/ChangeLog:

* mangle.c (write_base_ref): New.
(write_expression): Use it for base field COMPONENT_REFs.
* pt.c (invalid_tparm_referent_p): Canonicalize the type
of array offsets.  Allow subobjects.

gcc/c-family/ChangeLog:

* c-cppbuiltin.c (c_cpp_builtins): Update
__cpp_nontype_template_args for C++20.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/nontype2.C: No error in C++20.
* g++.dg/template/nontype25.C: No error in C++20.
* g++.dg/template/nontype8.C: No error in C++20.
* g++.dg/cpp2a/nontype-subob1.C: New test.
* g++.dg/cpp2a/nontype-subob2.C: New test.
* g++.dg/cpp1z/nontype3.C: Now C++17-only.
* g++.dg/cpp2a/feat-cxx2a.C: Adjust expected value.
gcc/c-family/c-cppbuiltin.c
gcc/cp/mangle.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/nontype2.C
gcc/testsuite/g++.dg/cpp1z/nontype3.C
gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
gcc/testsuite/g++.dg/cpp2a/nontype-subob1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nontype-subob2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/nontype25.C
gcc/testsuite/g++.dg/template/nontype8.C