@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
1259
1259
if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
1260
1260
return true;
1261
1261
1262
+ // Is the function New an overload of the function Old?
1263
+ QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
1264
+ QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
1265
+
1266
+ // Compare the signatures (C++ 1.3.10) of the two functions to
1267
+ // determine whether they are overloads. If we find any mismatch
1268
+ // in the signature, they are overloads.
1269
+
1270
+ // If either of these functions is a K&R-style function (no
1271
+ // prototype), then we consider them to have matching signatures.
1272
+ if (isa<FunctionNoProtoType>(OldQType.getTypePtr()) ||
1273
+ isa<FunctionNoProtoType>(NewQType.getTypePtr()))
1274
+ return false;
1275
+
1276
+ const auto *OldType = cast<FunctionProtoType>(OldQType);
1277
+ const auto *NewType = cast<FunctionProtoType>(NewQType);
1278
+
1279
+ // The signature of a function includes the types of its
1280
+ // parameters (C++ 1.3.10), which includes the presence or absence
1281
+ // of the ellipsis; see C++ DR 357).
1282
+ if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
1283
+ return true;
1284
+
1285
+ // For member-like friends, the enclosing class is part of the signature.
1286
+ if ((New->isMemberLikeConstrainedFriend() ||
1287
+ Old->isMemberLikeConstrainedFriend()) &&
1288
+ !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
1289
+ return true;
1290
+
1291
+ // Compare the parameter lists.
1292
+ // This can only be done once we have establish that friend functions
1293
+ // inhabit the same context, otherwise we might tried to instantiate
1294
+ // references to non-instantiated entities during constraint substitution.
1295
+ // GH78101.
1262
1296
if (NewTemplate) {
1263
1297
// C++ [temp.over.link]p4:
1264
1298
// The signature of a function template consists of its function
@@ -1296,34 +1330,6 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
1296
1330
return true;
1297
1331
}
1298
1332
1299
- // Is the function New an overload of the function Old?
1300
- QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
1301
- QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
1302
-
1303
- // Compare the signatures (C++ 1.3.10) of the two functions to
1304
- // determine whether they are overloads. If we find any mismatch
1305
- // in the signature, they are overloads.
1306
-
1307
- // If either of these functions is a K&R-style function (no
1308
- // prototype), then we consider them to have matching signatures.
1309
- if (isa<FunctionNoProtoType>(OldQType.getTypePtr()) ||
1310
- isa<FunctionNoProtoType>(NewQType.getTypePtr()))
1311
- return false;
1312
-
1313
- const FunctionProtoType *OldType = cast<FunctionProtoType>(OldQType);
1314
- const FunctionProtoType *NewType = cast<FunctionProtoType>(NewQType);
1315
-
1316
- // The signature of a function includes the types of its
1317
- // parameters (C++ 1.3.10), which includes the presence or absence
1318
- // of the ellipsis; see C++ DR 357).
1319
- if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
1320
- return true;
1321
-
1322
- // For member-like friends, the enclosing class is part of the signature.
1323
- if ((New->isMemberLikeConstrainedFriend() ||
1324
- Old->isMemberLikeConstrainedFriend()) &&
1325
- !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
1326
- return true;
1327
1333
const auto *OldMethod = dyn_cast<CXXMethodDecl>(Old);
1328
1334
const auto *NewMethod = dyn_cast<CXXMethodDecl>(New);
1329
1335
0 commit comments