diff --git a/src/models/t5.cpp b/src/models/t5.cpp
--- a/llama.cpp/src/models/t5.cpp
+++ b/llama.cpp/src/models/t5.cpp
@@ -106,6 +106,12 @@ void llama_model_t5::load_arch_tensors(llama_model_loader &) {
     }
 }
 
+// Forward-declare the explicit specializations so that the std::make_unique
+// calls below see them before triggering implicit instantiation. Required
+// when compiling with -std=gnu++23 on clang.
+template <> llama_model_t5::graph<false>::graph(const llama_model & model, const llm_graph_params & params);
+template <> llama_model_t5::graph<true>::graph(const llama_model & model, const llm_graph_params & params);
+
 std::unique_ptr<llm_graph_context> llama_model_t5::build_arch_graph(const llm_graph_params & params) const {
     switch (params.gtype) {
         case LLM_GRAPH_TYPE_ENCODER:
