[cfe-dev] Invalid FriendDecl

Richard Smith richard at metafoo.co.uk
Wed Jan 14 13:39:00 PST 2015


On Wed, Jan 14, 2015 at 12:05 PM, victor <pedretti_86 at hotmail.com> wrote:

> 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>
> <http://llvm.org/bugs/show_bug.cgi?id=7190#attach_4928)>
> 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,
>

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.


> 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.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150114/6c2775e7/attachment.html>


More information about the cfe-dev mailing list