3 ms·
This does not compile: template<> class foo<int> { static_assert(false, "bad"); }; Reason: "false" is not a dependent name, so the compiler is allow
by Kristine1975 10y ago
This does not compile:
template<>
class foo<int> {
static_assert(false, "bad");
};
Reason: "false" is not a dependent name, so the compiler is allowed to check the static_assert when the template is being declared.
(Of course since this is a full specialization, there are no dependent names.)
See C++14 Standard §14.6.2 (Dependent Names) or http://en.cppreference.com/w/cpp/language/dependent_name http://en.cppreference.com/w/cpp/language/dependent_name (not sure how accurate that page is, though).
P.S: It might compile with Microsoft's Visual Studio, but only because that compiler doesn't implement two-phase name lookup, effectively turning every name into a dependent name.
- saynsedit 10y agoOh tricky! I did write that code on my phone so hopefully you'll excuse the sloppiness. Thanks to HN I have miraculously learned a new thing about C++ when I was sure I knew it all; though, not surprised. Also this dependent name behavior of static_assert seems to be a precedent for always checking static_assert in constexpr if.