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

[dcl.ambig.res] Ambiguity resolution for function and object declarations is ambiguous CWG2620 #2831

Closed
sdkrystian opened this issue Apr 18, 2019 · 5 comments · Fixed by #5984
Labels
cwg Issue must be reviewed by CWG.

Comments

@sdkrystian
Copy link
Contributor

sdkrystian commented Apr 18, 2019

http://eel.is/c++draft/dcl.decl#dcl.ambig.res-1 (Ambiguity resolution for function/object declaration) states that:

In that context, the choice is between a function declaration with [...] and an object declaration with [...].

and

Just as for the ambiguities mentioned in [stmt.ambig], the resolution is to consider any construct that could possibly be a declaration a declaration.

Both a function declaration and an object declaration are declarations, so it is unclear which will be chosen.

@sdkrystian
Copy link
Contributor Author

sdkrystian commented Apr 18, 2019

In addition to this, this wording does not cover the declaration of a reference being ambiguous with a the declaration of a function returning a reference.
Ex:

int x;
int& y(int(x)); 

@zygoloid zygoloid added the cwg Issue must be reviewed by CWG. label Apr 18, 2019
@zygoloid
Copy link
Member

I believe the intended interpretation is "the resolution is to consider the longest sequence of tokens that could possibly constitute a declarator to form a declarator". (In your example, the (int(x)) could be part of a declarator, so the declaration is disambiguated as a function declaration.)

I'd like CWG to look at this, in case my belief above is incorrect :)

@cpplearner
Copy link
Contributor

My understanding is that the ambiguity arises because int(x) can be treated as a parameter declaration or an initializer, and the "resolution" is to consider it as a parameter declaration.

[dcl.dcl]/10 seems to suggest that anything that's not a typedef declaration or function declaration is a object declaration, so it does seem to cover declaration of a reference.

@sdkrystian
Copy link
Contributor Author

Both of your interpretations work, but I believe the wording should be changed in order to make it clearer as to what it means.

@RealLitb
Copy link

[dcl.dcl]/10 seems to suggest that anything that's not a typedef declaration or function declaration is a object declaration, so it does seem to cover declaration of a reference.

I think this is #1280

@jensmaurer jensmaurer changed the title [dcl.ambig.res] Ambiguity resolution for function and object declarations is ambiguous [dcl.ambig.res] Ambiguity resolution for function and object declarations is ambiguous CWG2620 Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment