@@ -24,8 +24,13 @@ static bool hasPrivateConstructor(const CXXRecordDecl *RD) {
24
24
static bool isDerivedParameterBefriended (const CXXRecordDecl *CRTP,
25
25
const NamedDecl *Param) {
26
26
return llvm::any_of (CRTP->friends (), [&](const FriendDecl *Friend) {
27
- const auto *TTPT =
28
- dyn_cast<TemplateTypeParmType>(Friend->getFriendType ()->getType ());
27
+ const TypeSourceInfo *const FriendType = Friend->getFriendType ();
28
+ if (!FriendType) {
29
+ return false ;
30
+ }
31
+
32
+ const auto *const TTPT =
33
+ dyn_cast<TemplateTypeParmType>(FriendType->getType ());
29
34
30
35
return TTPT && TTPT->getDecl () == Param;
31
36
});
@@ -34,7 +39,12 @@ static bool isDerivedParameterBefriended(const CXXRecordDecl *CRTP,
34
39
static bool isDerivedClassBefriended (const CXXRecordDecl *CRTP,
35
40
const CXXRecordDecl *Derived) {
36
41
return llvm::any_of (CRTP->friends (), [&](const FriendDecl *Friend) {
37
- return Friend->getFriendType ()->getType ()->getAsCXXRecordDecl () == Derived;
42
+ const TypeSourceInfo *const FriendType = Friend->getFriendType ();
43
+ if (!FriendType) {
44
+ return false ;
45
+ }
46
+
47
+ return FriendType->getType ()->getAsCXXRecordDecl () == Derived;
38
48
});
39
49
}
40
50
@@ -95,6 +105,10 @@ void CrtpConstructorAccessibilityCheck::check(
95
105
const CXXRecordDecl *CRTPDeclaration =
96
106
CRTPInstantiation->getSpecializedTemplate ()->getTemplatedDecl ();
97
107
108
+ if (!CRTPDeclaration->hasDefinition ()) {
109
+ return ;
110
+ }
111
+
98
112
const auto *DerivedTemplateParameter =
99
113
getDerivedParameter (CRTPInstantiation, DerivedRecord);
100
114
0 commit comments