]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Validate external linkage definitions in header units [PR116401]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 7 Sep 2024 15:37:28 +0000 (01:37 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 20 Dec 2024 01:57:25 +0000 (12:57 +1100)
commit71732eafedbd30355e752bf873d355fbcd0e076f
tree0bda80bab4974196b92f957138b5bdfae8c55477
parentfde64d1180408128a2f33e5326a3a7876926e2a3
c++/modules: Validate external linkage definitions in header units [PR116401]

[module.import] p6 says "A header unit shall not contain a definition of
a non-inline function or variable whose name has external linkage."

This patch implements this requirement, and cleans up some issues in the
testsuite where this was already violated.  To handle deduction guides
we mark them as inline, since although we give them a definition for
implementation reasons, by the standard they have no definition, and so
we should not error in this case.

PR c++/116401

gcc/cp/ChangeLog:

* decl.cc (grokfndecl): Mark deduction guides as 'inline'.
* module.cc (check_module_decl_linkage): Implement checks for
non-inline external linkage definitions in headers.

gcc/testsuite/ChangeLog:

* g++.dg/modules/macro-4_c.H: Add missing 'inline'.
* g++.dg/modules/pr106761.h: Likewise.
* g++.dg/modules/pr98843_b.H: Likewise.
* g++.dg/modules/pr99468.H: Likewise.
* g++.dg/modules/pragma-1_a.H: Likewise.
* g++.dg/modules/tpl-ary-1.h: Likewise.
* g++.dg/modules/hdr-2.H: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl.cc
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/hdr-2.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/macro-4_c.H
gcc/testsuite/g++.dg/modules/pr106761.h
gcc/testsuite/g++.dg/modules/pr98843_b.H
gcc/testsuite/g++.dg/modules/pr99468.H
gcc/testsuite/g++.dg/modules/pragma-1_a.H
gcc/testsuite/g++.dg/modules/tpl-ary-1.h