Skip to content

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

Description

@opensdh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions