https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88628
--- Comment #5 from merukun1125 at docomo dot ne.jp --- (In reply to Jakub Jelinek from comment #4) > lambda is AFAIK a local class, so you need to instantiate it. So it is more > similar to: > #include <type_traits> > > template<typename T> > constexpr bool run() { return false; } > > template<typename T> > T get() { > struct S {}; > if constexpr (std::is_same_v<int, T>) return 0; > else static_assert(run <S> (), "Lambda expression is evaluated."); > } > > int main() { > get<int>(); > } > which also compiles fine (and doesn't compile if you use say int or > something non-dependent in run template-id). I'm sorry, I was mistaken. If a lambda expression is defined as a local class, it becomes as follows: #include <type_traits> template<typename T> T get() { struct S { auto operator()() const -> decltype(false) { return false; } }; if constexpr (std::is_same_v<int, T>) return 0; else static_assert(S{}(), "Lambda expression is evaluated."); } int main() { get<int>(); } This code does not fail to compile because the compiler seems to need T to determine the type of S. https://wandbox.org/permlink/QtGF6wpvPr9rlhQ1 I was misunderstood as follows: #include <type_traits> struct S { // A type that does not depend on template parameter T auto operator()() const -> decltype(false) { return false; } }; template<typename T> T get() { if constexpr (std::is_same_v<int, T>) return 0; else static_assert(S{}(), "Lambda expression is evaluated."); } int main() { get<int>(); } This code fail to compile. https://wandbox.org/permlink/628XClL8M3dnkD1Q If you do not mind, please tell me the place if there is a place where lambda expressions are defined as local classes in n4659 or n4791.