I noticed a probable bug in GCC 7.X but I can't find anything recognizing this bug anywhere. It would be nice to know if this was ever reported as a compiler bug or was hidden and until you know about it, you will assume that it works as it should. Especially that the feature is listed as supported for this version.
Until now I used this check to determine if I can use template auto patameters.
#if (__cpp_template_auto >= 201606L) || (__cpp_nontype_template_parameter_auto >= 201606L)
#define TEMPLATE_AUTO_AVAILABLE 1
#endif
In older code you'd have to declare template like that:
template <typename EnumType, EnumType enumValue>
auto func() { exclusive version for EnumType::enumValue }
Then call it like that:
auto value = func<MyEnumType, MyEnumType::value>();
With auto template parameter it is tempting to use it like this:
template <auto enumValue>
auto func() { exclusive version for decltype(enumValue)::enumValue }
auto value = func<MyEnumType::value>();
The problem is that it is not an equivalent in GCC 7.X and can lead to nasty bugs.
Minimal example code:
enum class FirstEnum : short { firstVal = 7 };
enum class SecondEnum : size_t { secondVal = 7 };
template <typename T>
struct TypeName;
template <>
struct TypeName<FirstEnum>
{
static constexpr auto name = "FirstEnum";
};
template <>
struct TypeName<SecondEnum>
{
static constexpr auto name = "SecondEnum";
};
template <auto t>
void func()
{
std::cout << TypeName<decltype(t)>::name << std::endl;
}
int main()
{
func<FirstEnum::firstVal>();
func<SecondEnum::secondVal>();
}