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

CWG2963 [stmt.ambig] Paradoxical variable-or-function declaration #643

Open
opensdh opened this issue Nov 17, 2024 · 1 comment
Open

CWG2963 [stmt.ambig] Paradoxical variable-or-function declaration #643

opensdh opened this issue Nov 17, 2024 · 1 comment

Comments

@opensdh
Copy link

opensdh commented Nov 17, 2024

Reference (section label): [stmt.ambig]

Issue description:

Consider

struct A {
  static int b;
};
struct B {
  B(int);
  B operator()();
  using b=int;
};

namespace P {
  B A(decltype(A())::b);
}

If P::A is a variable, the A in what is then its initializer refers to it, so the decltype is B and B::b is int, so its declaration should be a function declaration instead. If P::A is a function, it's not available for lookup in its parameter list (which is part of its declarator; see [basic.scope.pdecl]/1), so A is ::A, the decltype is A, and A::b is a variable, so its declaration should be a variable declaration after all.

Implmentations agree that P::A is a variable but use the interpretation of decltype(A()) that finds ::A, presumably from some trial parse.

Suggested resolution:

Perhaps the prohibition on using A in a template argument in its initializer ([stmt.ambig]/3) needs to be extended to decltype, although it's not clear that there is no third way to refer to a variable or something shadowed by it in its own initializer in a way that would produce a type or value respectively.

@jensmaurer
Copy link
Member

CWG2963

@jensmaurer jensmaurer changed the title [stmt.ambig] Paradoxical variable-or-function declaration CWG2963 [stmt.ambig] Paradoxical variable-or-function declaration Dec 5, 2024
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