https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109001
Bug ID: 109001
Summary: “no declaration matches” for complicated non-type
template parameters
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: headch at gmail dot com
Target Milestone: ---
I’m reasonably certain (but not completely) that this is valid code:
#include <algorithm>
#include <cstddef>
template<size_t x>
class C {
public:
template<size_t y>
C<std::max(x, y)> set();
};
template<size_t x>
template<size_t y>
C<std::max(x, y)> C<x>::set() {
return {};
}
however, GCC rejects it with “error: no declaration matches ‘C<std::max<long
unsigned int>(x, y)> C<x>::set()’” on the out-of-body function definition. This
is accepted in GCC 11.3, as well as the latest versions of Clang and MSVC on
gcc.godbolt.org. Interestingly, GCC 12 also accepts the code if I change the
function definition (just the definition, not the in-body declaration) to use
trailing-return-type syntax:
#include <algorithm>
#include <cstddef>
template<size_t x>
class C {
public:
template<size_t y>
C<std::max(x, y)> set();
};
template<size_t x>
template<size_t y>
auto C<x>::set() -> C<std::max(x, y)> {
return {};
}