c++: Strengthen checks on 'main'
commit292fc21a8d7aa2f16e61ac941e22ada6ddd85500
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 11 May 2024 12:25:44 +0000 (11 22:25 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Wed, 22 May 2024 00:30:41 +0000 (22 10:30 +1000)
treea93b53992981677d0bc2e4cd4152d15d3d75c91b
parentbad96a02c486fb03e328a7455c9bc97cc85c02fe
c++: Strengthen checks on 'main'

This patch adds some missing requirements for legal main declarations,
as according to [basic.start.main] p2.

gcc/cp/ChangeLog:

* decl.cc (grokfndecl): Check for main functions with language
linkage or module attachment.
(grokvardecl): Check for extern 'C' entities named main.

gcc/testsuite/ChangeLog:

* g++.dg/abi/main.C: Check pedwarn for main with linkage-spec.
* g++.dg/modules/contracts-1_b.C: Don't declare main in named
module.
* g++.dg/modules/contracts-3_b.C: Likewise.
* g++.dg/modules/contracts-4_d.C: Likewise.
* g++.dg/modules/horcrux-1_a.C: Export declarations, so that...
* g++.dg/modules/horcrux-1_b.C: Don't declare main in named
module.
* g++.dg/modules/main-1.C: New test.
* g++.dg/parse/linkage5.C: New test.
* g++.dg/parse/linkage6.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/decl.cc
gcc/testsuite/g++.dg/abi/main.C
gcc/testsuite/g++.dg/modules/contracts-1_b.C
gcc/testsuite/g++.dg/modules/contracts-3_b.C
gcc/testsuite/g++.dg/modules/contracts-4_d.C
gcc/testsuite/g++.dg/modules/horcrux-1_a.C
gcc/testsuite/g++.dg/modules/horcrux-1_b.C
gcc/testsuite/g++.dg/modules/main-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/linkage5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/linkage6.C [new file with mode: 0644]