Title
Scope after declarator-id before determining correspondence
Status
open
Section
6.4.6 [basic.scope.namespace]
Submitter
Hubert Tong

Created on 2025-04-12.00:00:00 last changed 2 months ago

Messages

Date: 2025-04-12.00:00:00

(From submission #698.)

Consider:

  namespace N {
    inline namespace A {
      constexpr int f(int *);
    }
    inline namespace B {
      constexpr int f(long *);
    }
  } // namespace N

  template <typename T> struct Q { using type = long; };

  constexpr int N::f(Q<struct X *>::type *) { return 42; } // #1

  namespace N {
    inline namespace B {
      struct X {};
    }
  } // namespace N
  template <> struct Q<N::B::X *>; // explicit specialization after implicit instantiation
  static_assert(N::B::f(0) == 42);

According to 6.4.6 [basic.scope.namespace] paragraph 1, the target scope of the declaration #1 is N::B. This is known only after establishing correspondence with the two earlier candidate declarations of f. However, a target scope for the elaborated-type-specifier struct X at #1 must be determined prior to establishing correspondence.

It would be reasonable to use N as the target scope for struct X, i.e. the scope named by the nested-name-specififer.

History
Date User Action Args
2025-04-12 00:00:00admincreate