https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120917

--- Comment #17 from Frank Heckenbach <f.heckenb...@fh-soft.de> ---
Maybe I've found a work-around. I took the is_instance_of_v template from
https://indii.org/blog/is-type-instantiation-of-template/ and turned it into a
concept, so I can replace:

  void f (S <auto>);
  void g (T <auto, auto>);

with:

  void f (instance_of <S> auto);
  void g (instance_of <T> auto);

which at least keeps the required changes localized.

I think it won't work with "partially auto instantiations" such as:

  void g (T <auto, int>);

But fortunately I don't have many of them.

Since I'm not so well versed with concepts yet, can you please confirm whether
this is effectively equivalent?

% cat test.cpp
#include <type_traits>

template<typename T, template<typename...> typename U>
inline constexpr bool is_instance_of_v = std::false_type{};

template<template<typename...> typename U, typename... Vs>
inline constexpr bool is_instance_of_v<U<Vs...>,U> = std::true_type{};

template <typename T, template<typename...> typename U>
concept instance_of = is_instance_of_v<T, U>;

template <typename T> struct S { };

void f (S <auto>) { }
void f_ (instance_of <S> auto) { }

int main ()
{
  S <double> a;

  // OK
  f  (a);
  f_ (a);
  f  (S <int> ());
  f_ (S <int> ());

  // error
  // f  (1);
  // f_ (1);
  // f  (nullptr);
  // f_ (nullptr);
}
% g++-14 --std=c++23 -c -Wall -Wextra -pedantic -Wpedantic -pedantic-errors
-fconcepts-ts test.cpp 
cc1plus: note: '-fconcepts-ts' is deprecated and will be removed in GCC 15;
please convert your code to C++20 concepts
%

Reply via email to