[cfe-dev] Invalid FriendDecl

victor pedretti_86 at hotmail.com
Thu Jan 15 03:05:40 PST 2015


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.

Date: Wed, 14 Jan 2015 13:39:00 -0800
Subject: Re: [cfe-dev] Invalid FriendDecl
From: richard at metafoo.co.uk
To: pedretti_86 at hotmail.com
CC: cfe-dev at cs.uiuc.edu

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), 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/20150115/a994c44d/attachment.html>


More information about the cfe-dev mailing list