This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2963. Paradoxical variable-or-function declaration

Section: 8.9  [stmt.ambig]     Status: open     Submitter: Davis Herring     Date: 2024-11-17

(From submission #643.)

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, then decltype(A())::b is its initializer, and the A therein refers to the variable. That implies that the decltype is B and B::b is int, thus the declaration should be a function declaration instead.

If P::A is a function, then its name is not available for lookup in its parameter list (see 6.4.2 [basic.scope.pdecl] paragraph 1), so A is ::A and A::b is a varaible, thus the declaration should be a variable declaration instead.

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

Suggested resolution:

Extend the prohibition on using A in a template argument (8.9 [stmt.ambig] paragraph 3 to decltype.