Go to file
Jakub Jelinek 32c3a75390 c++: Implement P0466R5 __cpp_lib_is_layout_compatible compiler helpers [PR101539]
The following patch implements __is_layout_compatible trait and
__builtin_is_corresponding_member helper function for the
std::is_corresponding_member template function.

As the current definition of layout compatible type has various problems,
which result e.g. in corresponding members in layout compatible types having
different member offsets, the patch anticipates some changes to the C++
standard:
1) class or enumeral types aren't layout compatible if they have different
   alignment or size
2) if two members have different offsets, they can't be corresponding members
   ([[no_unique_address]] with empty types can change that, or alignas
   on the member decls)
3) in unions, bitfields can't correspond to non-unions, or bitfields can't
   correspond to bitfields with different widths, or members with
   [[no_unique_address]] can't correspond to members without that attribute

__builtin_is_corresponding_member for anonymous structs (GCC extension) will
recurse into the anonymous structs.  For anonymous unions it will emit
a sorry if it can't prove such member types can't appear in the
anonymous unions or anonymous aggregates in that union, because
corresponding member is defined only using common initial sequence which is
only defined for std-layout non-union class types and so I have no idea what
to do otherwise in that case.

2021-08-17  Jakub Jelinek  <jakub@redhat.com>

	PR c++/101539
gcc/c-family/
	* c-common.h (enum rid): Add RID_IS_LAYOUT_COMPATIBLE.
	* c-common.c (c_common_reswords): Add __is_layout_compatible.
gcc/cp/
	* cp-tree.h (enum cp_trait_kind): Add CPTK_IS_LAYOUT_COMPATIBLE.
	(enum cp_built_in_function): Add CP_BUILT_IN_IS_CORRESPONDING_MEMBER.
	(fold_builtin_is_corresponding_member, next_common_initial_seqence,
	layout_compatible_type_p): Declare.
	* parser.c (cp_parser_primary_expression): Handle
	RID_IS_LAYOUT_COMPATIBLE.
	(cp_parser_trait_expr): Likewise.
	* cp-objcp-common.c (names_builtin_p): Likewise.
	* constraint.cc (diagnose_trait_expr): Handle
	CPTK_IS_LAYOUT_COMPATIBLE.
	* decl.c (cxx_init_decl_processing): Register
	__builtin_is_corresponding_member builtin.
	* constexpr.c (cxx_eval_builtin_function_call): Handle
	CP_BUILT_IN_IS_CORRESPONDING_MEMBER builtin.
	* semantics.c (is_corresponding_member_union,
	is_corresponding_member_aggr, fold_builtin_is_corresponding_member):
	New functions.
	(trait_expr_value): Handle CPTK_IS_LAYOUT_COMPATIBLE.
	(finish_trait_expr): Likewise.
	* typeck.c (next_common_initial_seqence, layout_compatible_type_p):
	New functions.
	* cp-gimplify.c (cp_gimplify_expr): Fold
	CP_BUILT_IN_IS_CORRESPONDING_MEMBER.
	(cp_fold): Likewise.
	* tree.c (builtin_valid_in_constant_expr_p): Handle
	CP_BUILT_IN_IS_CORRESPONDING_MEMBER.
	* cxx-pretty-print.c (pp_cxx_trait_expression): Handle
	CPTK_IS_LAYOUT_COMPATIBLE.
	* class.c (remove_zero_width_bit_fields): Remove.
	(layout_class_type): Don't call it.
gcc/testsuite/
	* g++.dg/cpp2a/is-corresponding-member1.C: New test.
	* g++.dg/cpp2a/is-corresponding-member2.C: New test.
	* g++.dg/cpp2a/is-corresponding-member3.C: New test.
	* g++.dg/cpp2a/is-corresponding-member4.C: New test.
	* g++.dg/cpp2a/is-corresponding-member5.C: New test.
	* g++.dg/cpp2a/is-corresponding-member6.C: New test.
	* g++.dg/cpp2a/is-corresponding-member7.C: New test.
	* g++.dg/cpp2a/is-corresponding-member8.C: New test.
	* g++.dg/cpp2a/is-layout-compatible1.C: New test.
	* g++.dg/cpp2a/is-layout-compatible2.C: New test.
	* g++.dg/cpp2a/is-layout-compatible3.C: New test.
2021-08-17 21:18:29 +02:00
INSTALL
c++tools Daily bump. 2021-07-22 00:16:46 +00:00
config Daily bump. 2021-07-10 00:16:53 +00:00
contrib Daily bump. 2021-08-11 00:16:27 +00:00
fixincludes Daily bump. 2021-07-07 00:17:12 +00:00
gcc c++: Implement P0466R5 __cpp_lib_is_layout_compatible compiler helpers [PR101539] 2021-08-17 21:18:29 +02:00
gnattools Daily bump. 2021-05-08 00:16:27 +00:00
gotools Daily bump. 2021-02-03 00:16:23 +00:00
include Daily bump. 2021-07-25 00:16:22 +00:00
intl Daily bump. 2021-06-15 00:16:37 +00:00
libada
libatomic Daily bump. 2021-07-22 00:16:46 +00:00
libbacktrace Daily bump. 2021-08-14 00:16:29 +00:00
libcc1 Darwin, libcc1: Handle hosts with mdynamic-no-pic support. 2021-08-17 20:03:56 +01:00
libcody Daily bump. 2021-04-07 00:16:39 +00:00
libcpp c++: Add C++20 #__VA_OPT__ support 2021-08-17 09:27:57 +02:00
libdecnumber Daily bump. 2021-05-04 00:16:53 +00:00
libffi Daily bump. 2021-07-10 00:16:53 +00:00
libgcc Daily bump. 2021-08-17 00:16:32 +00:00
libgfortran Daily bump. 2021-08-11 00:16:27 +00:00
libgo libgo: various fixes for Solaris support 2021-08-14 17:34:52 -07:00
libgomp Fortran: Implement OpenMP 5.1 scope construct 2021-08-17 15:51:03 +02:00
libiberty Daily bump. 2021-07-01 00:16:41 +00:00
libitm Daily bump. 2021-06-18 00:16:58 +00:00
libobjc
liboffloadmic Daily bump. 2021-05-26 00:16:41 +00:00
libphobos Daily bump. 2021-06-12 00:16:27 +00:00
libquadmath Daily bump. 2021-06-09 00:16:30 +00:00
libsanitizer Daily bump. 2021-08-12 00:16:28 +00:00
libssp
libstdc++-v3 libstdc++: Avoid illegal argument to verbose in dg-test callback, continued 2021-08-17 21:05:27 +02:00
libvtv
lto-plugin Daily bump. 2021-06-26 00:16:39 +00:00
maintainer-scripts Daily bump. 2021-05-15 00:16:27 +00:00
zlib
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore Add cscope.out to git ignore. 2021-06-24 16:51:40 +05:30
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog Daily bump. 2021-08-10 00:16:28 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
MAINTAINERS MAINTAINERS: Add myself for write after approval 2021-08-09 09:59:44 +08:00
Makefile.def Darwin, configury : Allow for specification and detection of dsymutil. 2021-07-05 20:40:45 +01:00
Makefile.in Darwin, configury : Allow for specification and detection of dsymutil. 2021-07-05 20:40:45 +01:00
Makefile.tpl Darwin, configury : Allow for specification and detection of dsymutil. 2021-07-05 20:40:45 +01:00
README
ar-lib
compile
config-ml.in
config.guess config.sub, config.guess : Import upstream 2021-01-25. 2021-02-23 17:21:10 +08:00
config.rpath
config.sub config.sub, config.guess : Import upstream 2021-01-25. 2021-02-23 17:21:10 +08:00
configure Darwin, config: Revise host config fragment. 2021-07-09 17:35:57 +01:00
configure.ac Darwin, config: Revise host config fragment. 2021-07-09 17:35:57 +01:00
depcomp
install-sh
libtool-ldflags
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
symlink-tree
test-driver
ylwrap

README

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.