diff --git a/Tests/subset/data/GPOS_PairPos_Format2_ClassDef1_useClass0.subset.ttx b/Tests/subset/data/GPOS_PairPos_Format2_ClassDef1_useClass0.subset.ttx
new file mode 100644
index 000000000..3df9aa8f8
--- /dev/null
+++ b/Tests/subset/data/GPOS_PairPos_Format2_ClassDef1_useClass0.subset.ttx
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Tests/subset/data/GPOS_PairPos_Format2_ClassDef2_useClass0.subset.ttx b/Tests/subset/data/GPOS_PairPos_Format2_ClassDef2_useClass0.subset.ttx
new file mode 100644
index 000000000..dc599f139
--- /dev/null
+++ b/Tests/subset/data/GPOS_PairPos_Format2_ClassDef2_useClass0.subset.ttx
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Tests/subset/data/GPOS_PairPos_Format2_PR_2221.ttx b/Tests/subset/data/GPOS_PairPos_Format2_PR_2221.ttx
new file mode 100644
index 000000000..d5132d159
--- /dev/null
+++ b/Tests/subset/data/GPOS_PairPos_Format2_PR_2221.ttx
@@ -0,0 +1,322 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ gpos2_2_font5
+
+
+ Regular
+
+
+ gpos2_2_font5
+
+
+ gpos2_2_font5
+
+
+ Version1.0
+
+
+ gpos2_2_font5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 92 580 rmoveto
+ 13 6 13 7 14 4 54 16 184 1 9 -81 1 -13 -3 -13 -3 -14 -9 -45 -124 -14 -42 -8 rrcurveto
+ -2 -2 1 -1 hhcurveto
+ -2 vlineto
+ -30 -15 5 -40 35 -4 60 -5 62 -4 47 -43 83 -75 -108 -134 -82 -20 -75 -17 -101 91 -42 -14 -22 -8 -7 -18 10 -21 2 -2 2 -2 1 -2 10 -10 11 -3 10 2 rrcurveto
+ 2 2 -1 1 hhcurveto
+ 16 -7 15 -7 15 -7 33 -14 33 -14 35 -7 103 -18 81 94 48 78 51 83 -64 98 -77 36 -4 1 -3 2 -4 2 17 7 16 9 15 12 77 61 -32 107 -79 40 -91 47 -115 -9 -91 -40 rrcurveto
+ -27 -24 18 -37 36 7 rrcurveto
+ 408 -580 rmoveto
+ return
+
+
+ 41 642 rmoveto
+ 1 -2 1 -1 -1 vvcurveto
+ -7 2 -7 5 -5 vhcurveto
+ 15 -69 -71 -105 61 -45 71 -50 214 60 48 -116 9 -20 3 -24 -3 -22 -13 -128 -51 -35 -120 -6 -38 -1 -62 -5 -26 34 -29 22 -33 -28 16 -33 39 -51 75 0 59 2 83 5 76 21 49 69 rrcurveto
+ 25 36 0 48 11 42 19 72 -43 43 -42 45 -62 68 -159 -25 -76 26 -20 43 44 56 -6 66 101 14 102 -5 103 -1 37 7 0 42 -35 11 -109 1 -110 5 -108 -17 rrcurveto
+ -1 1 0 0 1 vvcurveto
+ -25 33 -45 -26 18 -38 rrcurveto
+ 407 -673 rmoveto
+ return
+
+
+
+
+
+ endchar
+
+
+ -107 callsubr
+ -107 callsubr
+ endchar
+
+
+ -107 callsubr
+ -106 callsubr
+ endchar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py
index 3f9348b95..6fa1bf608 100644
--- a/Tests/subset/subset_test.py
+++ b/Tests/subset/subset_test.py
@@ -762,6 +762,37 @@ class SubsetTest(unittest.TestCase):
subsetfont = TTFont(subsetpath)
self.expect_ttx(subsetfont, self.getpath("CmapSubsetTest.subset.ttx"), ["cmap"])
+ def test_GPOS_PairPos_Format2_useClass0(self):
+ # Check two things related to class 0 ('every other glyph'):
+ # 1) that it's reused for ClassDef1 when it becomes empty as the subset glyphset
+ # is intersected with the table's Coverage
+ # 2) that it is never reused for ClassDef2 even when it happens to become empty
+ # because of the subset glyphset. In this case, we don't keep a PairPosClass2
+ # subtable if only ClassDef2's class0 survived subsetting.
+ # The test font (from Harfbuzz test suite) is constructed to trigger these two
+ # situations depending on the input subset --text.
+ # https://github.com/fonttools/fonttools/pull/2221
+ _, fontpath = self.compile_font(
+ self.getpath("GPOS_PairPos_Format2_PR_2221.ttx"), ".ttf"
+ )
+ subsetpath = self.temp_path(".ttf")
+
+ for n, text in enumerate("!#", start=1):
+ expected_ttx = self.getpath(
+ f"GPOS_PairPos_Format2_ClassDef{n}_useClass0.subset.ttx"
+ )
+ with self.subTest(text=text, expected_ttx=expected_ttx):
+ subset.main(
+ [
+ fontpath,
+ f"--text='{text}'",
+ "--layout-features+=test",
+ "--output-file=%s" % subsetpath,
+ ]
+ )
+ subsetfont = TTFont(subsetpath)
+ self.expect_ttx(subsetfont, expected_ttx, ["GPOS"])
+
@pytest.fixture
def featureVarsTestFont():