Skip to content

[basic.start.main] Clarify what it means to "use" main CWG2811 #6563

Description

@eisenwave

The current wording in [basic.start.main] p3 is:

The function main shall not be used within a program.

There is no forward reference for what "use" refers to and the word doesn't seem to be defined anywhere, so I'm pretty sure this is meant to mean odr-use:

A function is odr-used if it is named by a potentially-evaluated expression or conversion.

- [basic.def.odr] p8

  1. Can we just replace "use" with "odr-use"?
  2. Is CWG intent clear enough for this to be non-editorial or is there more to it?

C++98 Wording

The function main shall not be used (3.2 [basic.def.odr]) within a program.

- [basic.start.main] p3

An object or non-overloaded function is used if its name appears in a potentially-evaluated expression.

- [basic.def.odr] p2

Activity

  1. eisenwave commented on Sep 12, 2023

    @eisenwave
    MemberAuthor

    Alternatively this could adopt the wording for deleted functions in [dcl.fct.def.delete] p2:

    A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed.

  2. eisenwave commented on Sep 12, 2023

    @eisenwave
    MemberAuthor

    @jensmaurer your paper replaced "use ([basic.def.odr])" with "use".

    Why is odr-use not the right interpretation here, and what is?

    C++98 used to define use. Did you make a typo and you meant to replace "use" with "odr-use" instead of just removing the reference to [basic.def.odr]?

  3. t3nsor commented on Sep 12, 2023

    @t3nsor
    Contributor

    Frustratingly, I can't find anything in the meeting minutes about why this change was made between N3154 and N3214. See https://stackoverflow.com/a/25298934/481267

    I don't think it's editorial. I think CWG should try to come to an agreement about what it's supposed to mean.

  4. eisenwave commented on Sep 12, 2023

    @eisenwave
    MemberAuthor

    @t3nsor I was initially confused too, but look at the C++98 wording I've edited into the post. In C++98, the paragraph for main literally references use (subsequently renamed to odr-use).

    It looks like a purely editorial issue where someone forgot to replace "use" with "odr-use" when the term was renamed.

    I don't see any strong reason why the renaming of "use" to "odr-use" should suddenly change the restrictions on main. That would be surprising and I don't think it is CWG intent.

  5. t3nsor commented on Sep 12, 2023

    @t3nsor
    Contributor

    No, look at the difference between N3154 and N3214. It appears to be intentional.

  6. eisenwave commented on Sep 12, 2023

    @eisenwave
    MemberAuthor

    You're probably right, but then what does "use" even mean? It used to have a definition but now it's pretty meaningless. There should at least be a note which clarifies what constitutes "use" of main.

  7. t3nsor commented on Sep 12, 2023

    @t3nsor
    Contributor

    That's the problem: I don't think anyone knows for sure what it means, so this should go to CWG. Especially since the language has evolved so much that there may be new questions to consider that may not have existed in C++11.

  8. jensmaurer commented on Sep 21, 2023

    @jensmaurer
    Member

    I'm pretty sure CWG left "use" in there because it wasn't clearly "odr-use" that was intended here, but the paper to introduce "odr-use" was important enough not to get hung up over it.

    We need answers for decltype(::main) as well as sizeof(&::main), for example. It's plausible that forming even an unevaluated pointer-to-main is hard to support on some platforms (because it might have a type that is not representable in C++).

    Going the "deleted function" route sounds promising.

  9. frederick-vs-ja commented on Aug 7, 2024

    @frederick-vs-ja
    Contributor

    Is this resolved together with CWG2811?

  10. changed the title [-][basic.start.main] Clarify what it means to "use" `main`[/-] [+][basic.start.main] Clarify what it means to "use" `main` CWG2811[/+] on Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions