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

Imprecise definition of unqualified name lookup for global and namespace scope. #3989

Closed
NicolBolas opened this issue May 9, 2020 · 1 comment

Comments

@NicolBolas
Copy link

[basic.lookup.unqual]/4-6 don't quite use formal terminology for certain things.

A name used in global scope, outside of any function, class or user-declared namespace, shall be declared before its use in global scope.

This defines the concept of "global scope". But where does the line get drawn for being "outside" of a function? Is the "inside" of the function the body of the function definition, or something else? Are the parameters or return values of a function declaration/definition considered "inside" or "outside"? The obvious intent is to talk about the function body (that names in a function body are not in the global scope), but it's not 100% clear.

Similar questions could be asked of class and namespaces.

Paragraph 5 has a different problem:

A name used in a user-declared namespace outside of the definition of any function or class shall be declared before its use in that namespace or before its use in a namespace enclosing its namespace.

Unlike "outside of a function", a function definition is a well-defined construct. However, a function definition includes its prototype: return value and parameters. Again, this is likely intended to mean the body of a function definition.

In paragraph 6, we have:

In the definition of a function that is a member of namespace N, a name used after the function's declarator-id shall be declared before its use in the block in which it is used or in one of its enclosing blocks ([stmt.block]) or shall be declared before its use in namespace N or, if N is a nested namespace, shall be declared before its use in one of N's enclosing namespaces.

The issue here is that return types can appear before the declarator-id, so that needs to be accounted for here.

@jensmaurer
Copy link
Member

jensmaurer commented May 9, 2020

The name lookup section has numerous issues, which are addressed by the wholesale rewrite in P1787 Declarations and where to find them cplusplus/papers#533.

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

2 participants