This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-05


2594. Disallowing a global function template main

Section: 6.9.3.1  [basic.start.main]     Status: CD6     Submitter: Jim X     Date: 2022-06-06

[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).

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 is ill-formed. The name main is not otherwise reserved.