Consider the following example:
#include <type_traits>
struct A {};
template <A const i> void f() {
static_assert(std::is_same_v<decltype(i), A const>); // #1
A& ar = i; // #2
}
int main() {
f<A{}>();
}
which both Clang(1) and GCC(1) rejects with the following two seemingly conflicting errors:
#1 error: static_assert failed due to requirement 'std::is_same_v<A, const A>' #2 error: binding reference of type 'A' to value of type 'const A' drops 'const' qualifier
Moreover, if we change the type of the non-type template parameter into a placeholder type as follows:
template <auto const i> void g() {
static_assert(std::is_same_v<decltype(i), A const>); // #1
A& ar = i; // #2
}
Then GCC accepts #1, whereas Clang rejects it (both reject #2 as above).
What is going on here, and which compiler is correct (if any)?
(1) GCC HEAD 11.0.0 20210117 and Clang HEAD 12.0.0 (20210118), -std=c++20.