gcc/libcc1
Nathaniel Shead fde64d1180 c++/modules: Check linkage for exported declarations
By [module.interface] p3, if an exported declaration is not within a
header unit, it shall not declare a name with internal linkage.

Unfortunately we cannot just do this within set_originating_module,
since at the locations its called the linkage for declarations are not
always fully determined yet.  We could move the calls but this causes
the checking assertion to fail as the originating module declaration may
have moved, and in general for some kinds of declarations it's not
always obvious where it should be moved to.

This patch instead introduces a new function to check that the linkage
of a declaration within a module is correct, to be called for all
declarations once their linkage is fully determined.

As a drive-by fix this patch also improves the source location of
namespace aliases to point at the identifier rather than the terminating
semicolon.

gcc/cp/ChangeLog:

	* cp-tree.h (check_module_decl_linkage): Declare.
	* decl2.cc (finish_static_data_member_decl): Check linkage.
	* module.cc (set_originating_module): Adjust comment.
	(check_module_decl_linkage): New function.
	* name-lookup.cc (do_namespace_alias): Build alias with
	specified location, check linkage.
	(pushtag): Check linkage.
	(push_namespace): Slightly clarify error message.
	* name-lookup.h (do_namespace_alias): Add location parameter.
	* parser.cc (cp_parser_namespace_alias_definition): Pass
	identifier location to do_namespace_alias.
	(cp_parser_alias_declaration): Check linkage.
	(cp_parser_init_declarator): Check linkage.
	(cp_parser_function_definition_after_declarator): Check linkage.
	(cp_parser_save_member_function_body): Check linkage.
	* pt.cc (finish_concept_definition): Mark as public, check
	linkage.

libcc1/ChangeLog:

	* libcp1plugin.cc (plugin_add_namespace_alias): Call
	do_namespace_alias with input_location.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/export-3.C: Adjust error message.
	* g++.dg/modules/export-6.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2024-12-20 12:57:24 +11:00
..
aclocal.m4
callbacks.cc Update copyright years. 2024-01-03 12:19:35 +01:00
callbacks.hh Update copyright years. 2024-01-03 12:19:35 +01:00
cc1plugin-config.h.in
ChangeLog Daily bump. 2024-09-21 00:16:55 +00:00
compiler-name.hh Update copyright years. 2024-01-03 12:19:35 +01:00
compiler.cc Update copyright years. 2024-01-03 12:19:35 +01:00
compiler.hh Update copyright years. 2024-01-03 12:19:35 +01:00
configure Config,Darwin: Allow for configuring Darwin to use embedded runpath. 2023-10-22 19:30:02 +01:00
configure.ac Update copyright years. 2024-01-03 12:19:35 +01:00
connection.cc Update copyright years. 2024-01-03 12:19:35 +01:00
connection.hh Update copyright years. 2024-01-03 12:19:35 +01:00
context.cc diagnostics: convert text hooks to use diagnostic_text_output_format [PR116613] 2024-09-20 18:51:55 -04:00
context.hh Update copyright years. 2024-01-03 12:19:35 +01:00
deleter.hh Update copyright years. 2024-01-03 12:19:35 +01:00
findcomp.cc Update copyright years. 2024-01-03 12:19:35 +01:00
findcomp.hh Update copyright years. 2024-01-03 12:19:35 +01:00
gdbctx.hh Update copyright years. 2024-01-03 12:19:35 +01:00
libcc1.cc Fix PR libcc1/113977 2024-02-29 08:50:06 -07:00
libcc1.sym
libcc1plugin.cc libcc1: fix <vector> include 2024-03-16 09:50:00 +01:00
libcc1plugin.sym
libcp1.cc Fix version negotiation in libcc1 plugins 2024-02-29 08:50:06 -07:00
libcp1plugin.cc c++/modules: Check linkage for exported declarations 2024-12-20 12:57:24 +11:00
libcp1plugin.sym
Makefile.am Update copyright years. 2024-01-03 12:19:35 +01:00
Makefile.in Darwin, libcc1: Handle hosts with mdynamic-no-pic support. 2021-08-17 20:03:56 +01:00
marshall-cp.hh Update copyright years. 2024-01-03 12:19:35 +01:00
marshall.cc Update copyright years. 2024-01-03 12:19:35 +01:00
marshall.hh Update copyright years. 2024-01-03 12:19:35 +01:00
names.cc Update copyright years. 2024-01-03 12:19:35 +01:00
names.hh Update copyright years. 2024-01-03 12:19:35 +01:00
rpc.hh Update copyright years. 2024-01-03 12:19:35 +01:00
status.hh Update copyright years. 2024-01-03 12:19:35 +01:00