Skip to content

Commit b6985ac

Browse files
committed
Sema: More flexible InvalidUseOfAddressOf
1 parent 1dedba1 commit b6985ac

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,9 +2728,17 @@ bool InvalidMethodRefInKeyPath::diagnoseAsError() {
27282728
return true;
27292729
}
27302730

2731+
SourceLoc InvalidUseOfAddressOf::getLoc() const {
2732+
auto *anchor = getAnchor();
2733+
2734+
if (auto *assign = dyn_cast<AssignExpr>(anchor))
2735+
anchor = assign->getSrc();
2736+
2737+
return anchor->getLoc();
2738+
}
2739+
27312740
bool InvalidUseOfAddressOf::diagnoseAsError() {
2732-
auto *anchor = cast<AssignExpr>(getAnchor());
2733-
emitDiagnostic(anchor->getSrc()->getLoc(), diag::extraneous_address_of);
2741+
emitDiagnostic(getLoc(), diag::extraneous_address_of);
27342742
return true;
27352743
}
27362744

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,10 @@ class InvalidUseOfAddressOf final : public FailureDiagnostic {
11581158
: FailureDiagnostic(root, cs, locator) {}
11591159

11601160
bool diagnoseAsError() override;
1161+
1162+
protected:
1163+
/// Compute location of the failure for diagnostic.
1164+
SourceLoc getLoc() const;
11611165
};
11621166

11631167
/// Diagnose an attempt return something from a function which

0 commit comments

Comments
 (0)