Template function definition extensions in Clang++

Viewed 74

It turns out that Clang compiler accepts certain non-standard variants of template function definitions.

In this example

#include <iostream>

template<> //#1
void foo(auto x) { std::cout << x; };

template<> //#2
void foo(int) requires(false) { std::cout << "int"; };

int main() { foo(1); }

#1 is a definition of new template function in C++20 style (with auto keyword), however it is not a template specialization, so the begging with template<> is not-standard.

And #2 is a full specialization, so it is not-template function by itself, and requires section is not expected here, but accepted (and ignored) by Clang.

The program prints int, demo: https://gcc.godbolt.org/z/xTzP177Gd

Are these simply Clang bugs, or they are some language extensions that can be used with a purpose?

0 Answers
Related