From 6284674e9e5396a2441c379bdcad00bfde8a65e0 Mon Sep 17 00:00:00 2001
From: kikairoya <kikairoya@gmail.com>
Date: Mon, 21 Apr 2025 23:30:13 +0900
Subject: [PATCH] [Cygwin] Internal class in
 explicitly-instantiation-declarated template should be instantiated

In-code comment says "explicit instantiation decl of the outer class
doesn't affect the inner class" but this behavior seems MSVC
specific, mingw-gcc and cygwin-gcc does not.
Clang should honor gcc's behavior.

This change fixes std::string compatibilty and resolves strange link
error (statically linked), strange crash (dynamically linked) using
libstdc++ on Cygwin.

HACK! only change behavior for Cygwin, not MinGW, because linking to
libc++ relies on the old behavior, even though it differs from GCC.

Co-authored-by: Jeremy Drake <github@jdrake.com>
---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 20bac0e56b..9b687c28bd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -4325,6 +4325,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
         continue;
 
       if (Context.getTargetInfo().getTriple().isOSWindows() &&
+          !Context.getTargetInfo().getTriple().isWindowsCygwinEnvironment() &&
           TSK == TSK_ExplicitInstantiationDeclaration) {
         // On Windows, explicit instantiation decl of the outer class doesn't
         // affect the inner class. Typically extern template declarations are
-- 
2.51.0.windows.1

