@@ -7501,8 +7501,7 @@ class DefaultedComparisonSynthesizer
7501
7501
VarDecl *EqualVD = S.Context.CompCategories.getInfoForType(StrongOrdering)
7502
7502
.getValueInfo(ComparisonCategoryResult::Equal)
7503
7503
->VD;
7504
- RetVal = S.BuildDeclarationNameExpr(
7505
- CXXScopeSpec(), DeclarationNameInfo(), EqualVD);
7504
+ RetVal = getDecl(EqualVD);
7506
7505
if (RetVal.isInvalid())
7507
7506
return StmtError();
7508
7507
RetVal = buildStaticCastToR(RetVal.get());
@@ -7527,10 +7526,14 @@ class DefaultedComparisonSynthesizer
7527
7526
}
7528
7527
7529
7528
private:
7529
+ ExprResult getDecl(ValueDecl *VD) {
7530
+ return S.BuildDeclarationNameExpr(
7531
+ CXXScopeSpec(), DeclarationNameInfo(VD->getDeclName(), Loc), VD);
7532
+ }
7533
+
7530
7534
ExprResult getParam(unsigned I) {
7531
7535
ParmVarDecl *PD = FD->getParamDecl(I);
7532
- return S.BuildDeclarationNameExpr(
7533
- CXXScopeSpec(), DeclarationNameInfo(PD->getDeclName(), Loc), PD);
7536
+ return getDecl(PD);
7534
7537
}
7535
7538
7536
7539
ExprPair getCompleteObject() {
@@ -7622,8 +7625,7 @@ class DefaultedComparisonSynthesizer
7622
7625
Stmt *InitStmt = new (S.Context) DeclStmt(DeclGroupRef(VD), Loc, Loc);
7623
7626
7624
7627
// cmp != 0
7625
- ExprResult VDRef = S.BuildDeclarationNameExpr(
7626
- CXXScopeSpec(), DeclarationNameInfo(Name, Loc), VD);
7628
+ ExprResult VDRef = getDecl(VD);
7627
7629
if (VDRef.isInvalid())
7628
7630
return StmtError();
7629
7631
llvm::APInt ZeroVal(S.Context.getIntWidth(S.Context.IntTy), 0);
@@ -7639,8 +7641,7 @@ class DefaultedComparisonSynthesizer
7639
7641
return StmtError();
7640
7642
7641
7643
// return cmp;
7642
- VDRef = S.BuildDeclarationNameExpr(
7643
- CXXScopeSpec(), DeclarationNameInfo(Name, Loc), VD);
7644
+ VDRef = getDecl(VD);
7644
7645
if (VDRef.isInvalid())
7645
7646
return StmtError();
7646
7647
StmtResult ReturnStmt = S.BuildReturnStmt(Loc, VDRef.get());
@@ -10235,11 +10236,25 @@ QualType Sema::CheckComparisonCategoryType(ComparisonCategoryType Kind,
10235
10236
assert(getLangOpts().CPlusPlus &&
10236
10237
"Looking for comparison category type outside of C++.");
10237
10238
10239
+ // Use an elaborated type for diagnostics which has a name containing the
10240
+ // prepended 'std' namespace but not any inline namespace names.
10241
+ auto TyForDiags = [&](ComparisonCategoryInfo *Info) {
10242
+ auto *NNS =
10243
+ NestedNameSpecifier::Create(Context, nullptr, getStdNamespace());
10244
+ return Context.getElaboratedType(ETK_None, NNS, Info->getType());
10245
+ };
10246
+
10238
10247
// Check if we've already successfully checked the comparison category type
10239
10248
// before. If so, skip checking it again.
10240
10249
ComparisonCategoryInfo *Info = Context.CompCategories.lookupInfo(Kind);
10241
- if (Info && FullyCheckedComparisonCategories[static_cast<unsigned>(Kind)])
10250
+ if (Info && FullyCheckedComparisonCategories[static_cast<unsigned>(Kind)]) {
10251
+ // The only thing we need to check is that the type has a reachable
10252
+ // definition in the current context.
10253
+ if (RequireCompleteType(Loc, TyForDiags(Info), diag::err_incomplete_type))
10254
+ return QualType();
10255
+
10242
10256
return Info->getType();
10257
+ }
10243
10258
10244
10259
// If lookup failed
10245
10260
if (!Info) {
@@ -10258,18 +10273,10 @@ QualType Sema::CheckComparisonCategoryType(ComparisonCategoryType Kind,
10258
10273
if (Info->Record->hasDefinition())
10259
10274
Info->Record = Info->Record->getDefinition();
10260
10275
10261
- // Use an elaborated type for diagnostics which has a name containing the
10262
- // prepended 'std' namespace but not any inline namespace names.
10263
- QualType TyForDiags = [&]() {
10264
- auto *NNS =
10265
- NestedNameSpecifier::Create(Context, nullptr, getStdNamespace());
10266
- return Context.getElaboratedType(ETK_None, NNS, Info->getType());
10267
- }();
10268
-
10269
- if (RequireCompleteType(Loc, TyForDiags, diag::err_incomplete_type))
10276
+ if (RequireCompleteType(Loc, TyForDiags(Info), diag::err_incomplete_type))
10270
10277
return QualType();
10271
10278
10272
- InvalidSTLDiagnoser UnsupportedSTLError{*this, Loc, TyForDiags};
10279
+ InvalidSTLDiagnoser UnsupportedSTLError{*this, Loc, TyForDiags(Info) };
10273
10280
10274
10281
if (!Info->Record->isTriviallyCopyable())
10275
10282
return UnsupportedSTLError(USS_NonTrivial);
0 commit comments