Title
Disallowing a global function template main
Status
cd6
Section
6.9.3.1 [basic.start.main]
Submitter
Jim X

Created on 2022-06-06.00:00:00 last changed 19 months ago

Messages

Date: 2022-06-17.22:55:11

Proposed resolution (approved by CWG 2022-06-17):

Change in 6.9.3.1 [basic.start.main] paragraph 3 and add bullets as follows:

... A program that declares
  • a variable main that belongs to the global scope, or
  • that declares a function main that belongs to the global scope and is attached to a named module, or
  • a function template main that belongs to the global scope, or
  • that declares an entity named main with C language linkage (in any namespace)
is ill-formed. The name main is not otherwise reserved.
Date: 2022-07-15.00:00:00

[Accepted at the July, 2022 meeting.]

Consider:

  template<class T>
  int main(T) {}

C++20 specified in 6.9.3.1 [basic.start.main] paragraph 2:

An implementation shall not predefine the main function. This function shall not be overloaded.

While it is unclear what "overloaded" means when multiple translation units are involved, it arguably disallowed function templates called main. This prohibition was removed with P1787R6 (Declarations and where to find them).

History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: ready -> cd6
2022-06-17 22:55:11adminsetmessages: + msg6854
2022-06-17 22:55:11adminsetstatus: open -> ready
2022-06-06 00:00:00admincreate