Title
Paradoxical variable-or-function declaration
Status
open
Section
8.9 [stmt.ambig]
Submitter
Davis Herring

Created on 2024-11-17.00:00:00 last changed 2 weeks ago

Messages

Date: 2024-12-05.22:33:53

Suggested resolution:

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

Date: 2024-11-17.00:00:00

(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.

History
Date User Action Args
2024-12-05 22:33:53adminsetmessages: + msg7908
2024-11-17 00:00:00admincreate