Title
Effect of concept template-head on parameter mappings
Status
open
Section
13.5.4 [temp.constr.normal]
Submitter
Hubert Tong

Created on 2024-12-24.00:00:00 last changed 1 month ago

Messages

Date: 2024-12-27.21:28:15

(From submission #659.)

Consider:

  template <auto> constexpr bool B = true;

  template <unsigned X0> concept C = B<X0>;
  template <unsigned short X1> concept C2 = C<X1>;

  template <unsigned X> void f() requires C<X>; // #1
  template <unsigned X> int f() requires C2<X> && true; // #2

  void g() {
    return f<65536>(); // should probably call #1
  }
  void h() {
    f<0>(); // ambiguous?
  }

The rules in 13.5.4 [temp.constr.normal] bullet 1.4 do not specify how the type of the non-type template parameter X1 in the definition of concept C2 affects the parameter mapping. There is implementation divergence: gcc and MSVC reject the call in g and accept the call in h, resolving to #2 in both cases. Clang and EDG accept the call in g (resolving to #1) and reject the call in h as ambiguous.

As a suggested resolution, introduce a shadow constraint that checks the validity of the template argument for the concept's template parameter when normalizing the use of C2 from #2. This would reject the call to #2 from g (choosing #1) and select #2 as more constrained for the call from h.

History
Date User Action Args
2024-12-24 00:00:00admincreate