Invalid FriendDecl

Hi everyone,

I have something like this in my code:

for(CXXRecordDecl::friend_iterator fi=c1->friend_begin(); fi != c1->friend_end(); fi++){
QualType qt = (*fi)->getFriendType()->getType();

}

When using this code to analyze the following “friend”:

inline friend QDebug operator<< (QDebug s, const Cursor& cursor)

I get this segmentation fault:

Program received signal SIGSEGV, Segmentation fault.
clang::TypeSourceInfo::getType (this=0x0) at /usr/local/include/clang/AST/Decl.h:66
66 QualType getType() const { return Ty; }

I have been searching for this issue and found this bug ()http://llvm.org/bugs/show_bug.cgi?id=7190#attach_4928)), where is said:

"In the attached testcase, clang will attempt to instantiate the friend decl which is invalid because 
Derived has not been declared."

I think that maybe this is my problem, I mean, that the friend decl is invalid because it has not been declared. But, how can I avoid the launch of this signal? I cannot prevent the appearance of this situation and I don’t want the program to terminate.

I hope you can help me with this. Thanks in advance.

Hi everyone,

I have something like this in my code:

for(CXXRecordDecl::friend_iterator fi=c1->friend_begin(); fi !=
c1->friend_end(); fi++){
   *QualType qt = (*fi)->getFriendType()->getType()*;
   ...
}

When using this code to analyze the following "friend":

inline *friend* QDebug operator<< (QDebug s, const Cursor& cursor)

I get this segmentation fault:

Program received signal SIGSEGV, Segmentation fault.
clang::TypeSourceInfo::getType (this=0x0) at
/usr/local/include/clang/AST/Decl.h:66
66 QualType getType() const { return Ty; }

I have been searching for this issue and found this bug (
<7190 – clang crashes trying to instantiate an invalid friend decl;
<7190 – clang crashes trying to instantiate an invalid friend decl)>
7190 – clang crashes trying to instantiate an invalid friend decl), where is said:

"In the attached testcase, clang will attempt to instantiate the friend decl which is invalid because
Derived has not been declared."

I think that maybe this is my problem,

No, it's not. You're calling 'getFriendType()' on a FriendDecl that
represents a friend function, not a friend type, so it returns nullptr. You
then try to call 'getType()' on a null pointer.

Ok, thank you Richard for your answer. Now I understand what a friendType is. Two friendDecl, but only the marked bold is a FriendType:
friend class A;
friend void a();

Thanks again.