@@ -2789,18 +2789,26 @@ namespace mrbind
27892789 // auto new_decl = ci->getSema().InstantiateFunctionDeclaration(func_templ, targs, decl->getSourceRange().getBegin());
27902790
27912791 { // Inspired by `sema::InstantiateFunctionDeclaration()`.
2792- auto loc = decl->getSourceRange ().getBegin ();
2793-
2794- // Which one to pick? This one looks kinda relevant.
2795- auto csc = clang::Sema::CodeSynthesisContext::ExplicitTemplateArgumentSubstitution;
2792+ /*
2793+ The way you test this is as following:
2794+ template <typename T = int> void foo() {}
2795+ template <typename T = int> std::enable_if_t<sizeof(T) == 42> bar() {}
2796+ And pass `--buggy-substitute-default-template-args`.
2797+ The first overload should be parsed, and the second overload should be silently skipped, rather than hard fail.
2798+ */
27962799
27972800 #if CLANG_VERSION_MAJOR >= 22
2798- clang::Sema::InstantiatingTemplate Inst (ci->getSema (), loc, func_templ, ml_targs.getInnermost (), csc);
2801+ // In v22 and newer, `InstantiatingTemplate` no longer acts as a SFINAE error trap. There's a new class for that now.
2802+ clang::Sema::SFINAETrap trap (ci->getSema ());
2803+ if (!trap.hasErrorOccurred ())
27992804 #else
2805+ auto loc = decl->getSourceRange ().getBegin ();
2806+ // Which one to pick? This one looks kinda relevant.
2807+ auto csc = clang::Sema::CodeSynthesisContext::ExplicitTemplateArgumentSubstitution;
28002808 clang::sema::TemplateDeductionInfo Info (loc);
28012809 clang::Sema::InstantiatingTemplate Inst (ci->getSema (), loc, func_templ, ml_targs.getInnermost (), csc, Info);
2802- #endif
28032810 if (!Inst.isInvalid ())
2811+ #endif
28042812 {
28052813 auto templated_decl = func_templ->getTemplatedDecl ();
28062814 clang::Sema::ContextRAII SavedContext (ci->getSema (), templated_decl);
0 commit comments