Skip to content

Commit fa5fb4a

Browse files
committed
Fix an uninitialization bug
1 parent 36199ce commit fa5fb4a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ std::optional<Location> toLocation(SourceManager &SM, SourceRange Range) {
391391

392392
class TypeInlayHintLabelPartBuilder
393393
: public TypeVisitor<TypeInlayHintLabelPartBuilder> {
394-
QualType Current;
394+
QualType CurrentType;
395395
ASTContext &Context;
396396
const PrintingPolicy &PP;
397397
std::vector<InlayHintLabelPart> &LabelChunks;
@@ -404,12 +404,13 @@ class TypeInlayHintLabelPartBuilder
404404
bool PreviousShouldAddLinksToTagTypes;
405405
CurrentTypeRAII(TypeInlayHintLabelPartBuilder &Builder, QualType New,
406406
bool ShouldAddLinksToTagTypes)
407-
: Builder(Builder), PreviousType(Builder.Current) {
408-
Builder.Current = New;
407+
: Builder(Builder), PreviousType(Builder.CurrentType),
408+
PreviousShouldAddLinksToTagTypes(Builder.ShouldAddLinksToTagTypes) {
409+
Builder.CurrentType = New;
409410
Builder.ShouldAddLinksToTagTypes = ShouldAddLinksToTagTypes;
410411
}
411412
~CurrentTypeRAII() {
412-
Builder.Current = PreviousType;
413+
Builder.CurrentType = PreviousType;
413414
Builder.ShouldAddLinksToTagTypes = PreviousShouldAddLinksToTagTypes;
414415
}
415416
};
@@ -511,13 +512,14 @@ class TypeInlayHintLabelPartBuilder
511512
bool ShouldAddLinksToTagTypes,
512513
llvm::StringRef Prefix,
513514
std::vector<InlayHintLabelPart> &LabelChunks)
514-
: Current(Current), Context(Context), PP(PP), LabelChunks(LabelChunks) {
515+
: CurrentType(Current), Context(Context), PP(PP),
516+
LabelChunks(LabelChunks) {
515517
LabelChunks.reserve(16);
516518
if (!Prefix.empty())
517519
addLabel(Prefix.str());
518520
}
519521

520-
void VisitType(const Type *) { addLabel(Current.getAsString(PP)); }
522+
void VisitType(const Type *) { addLabel(CurrentType.getAsString(PP)); }
521523

522524
void VisitTagType(const TagType *TT) {
523525
if (!ShouldAddLinksToTagTypes)

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct ExpectedHintLabelPiece {
6262
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &Stream,
6363
const ExpectedHintLabelPiece &Hint) {
6464
Stream << Hint.Label;
65-
if (!Hint.TargetRangeName)
65+
if (Hint.TargetRangeName)
6666
Stream << " that points to $" << Hint.TargetRangeName;
6767
return Stream;
6868
}
@@ -1769,12 +1769,15 @@ TEST(TypeHints, Links) {
17691769
ExpectedHintLabelPiece{
17701770
": NttpContainer<D, E, ScopedEnum::X, Enum::E>"},
17711771
Source)));
1772+
17721773
EXPECT_THAT(
17731774
HintAt(Hints, "5"),
17741775
ElementsAre(
17751776
HintLabelPieceMatcher(ExpectedHintLabelPiece{": Nested<"}, Source),
17761777
HintLabelPieceMatcher(
17771778
ExpectedHintLabelPiece{"Container", "Container"}, Source),
1779+
// We don't have links on the inner 'Class' because the location is
1780+
// where the 'auto' links to.
17781781
HintLabelPieceMatcher(ExpectedHintLabelPiece{"<int>>::Class<"},
17791782
Source),
17801783
HintLabelPieceMatcher(ExpectedHintLabelPiece{"Package", "Package"},

0 commit comments

Comments
 (0)