Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Eisenwave opened this issue Sep 12, 2023 · 8 comments
Open

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

Eisenwave opened this issue Sep 12, 2023 · 8 comments

Comments

@Eisenwave
Copy link
Contributor

Eisenwave commented Sep 12, 2023

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

@Eisenwave
Copy link
Contributor Author

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.

@Eisenwave
Copy link
Contributor Author

Eisenwave commented Sep 12, 2023

@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]?

@t3nsor
Copy link
Contributor

t3nsor commented Sep 12, 2023

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.

@Eisenwave
Copy link
Contributor Author

Eisenwave commented Sep 12, 2023

@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.

@t3nsor
Copy link
Contributor

t3nsor commented Sep 12, 2023

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

@Eisenwave
Copy link
Contributor Author

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.

@t3nsor
Copy link
Contributor

t3nsor commented Sep 12, 2023

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.

@jensmaurer
Copy link
Member

jensmaurer commented Sep 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants