Skip to content

Commit 14cfebc

Browse files
committed
Fix a crash in ClangImporter::Implementation::DiagnosticWalker::TraverseDecl
The call to `D->getBeginLoc` crashes when `D` is null. rdar://118899818
1 parent f6dba90 commit 14cfebc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,8 @@ ClangImporter::Implementation::DiagnosticWalker::DiagnosticWalker(
24262426

24272427
bool ClangImporter::Implementation::DiagnosticWalker::TraverseDecl(
24282428
clang::Decl *D) {
2429+
if (!D)
2430+
return true;
24292431
// In some cases, diagnostic notes about types (ex: built-in types) do not
24302432
// have an obvious source location at which to display diagnostics. We
24312433
// provide the location of the closest decl as a reasonable choice.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %target-swiftxx-frontend -typecheck -I %t/Inputs %t/test.swift -verify
4+
5+
//--- Inputs/module.modulemap
6+
module FriendClass {
7+
header "test.h"
8+
requires cplusplus
9+
export *
10+
}
11+
12+
//--- Inputs/test.h
13+
14+
template <class T>
15+
class B {
16+
~B() = delete;
17+
};
18+
19+
class D : public B<D> { // expected-note {{record 'D' is not automatically available}}
20+
friend class B<D>;
21+
};
22+
23+
//--- test.swift
24+
25+
import FriendClass
26+
27+
func test() {
28+
var v: D // expected-error {{cannot find type 'D' in scope}}
29+
}

0 commit comments

Comments
 (0)