Skip to content

Commit 5eb077b

Browse files
zillemarcotritao
authored andcommitted
Fixed a problem when walking the managed AST because friend templated
classes were seen as declared multiple times and resulted into a crash. Solves #975.
1 parent c41e89c commit 5eb077b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/CppParser/Parser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,23 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
887887
continue;
888888
WalkDeclaration(D);
889889
break;
890+
case Decl::Friend:
891+
{
892+
FriendDecl* FD = cast<FriendDecl>(D);
893+
auto decl = FD->getFriendDecl();
894+
895+
// Skip every friend declaration that isn't a function declaration
896+
if (decl && !isa<FunctionDecl>(decl))
897+
continue;
898+
WalkDeclaration(D);
899+
break;
900+
}
901+
case Decl::FriendTemplate:
902+
{
903+
// In this case always skip the declaration since, unlike Decl::Friend handled above,
904+
// it never is a declaration of a friend function or method
905+
break;
906+
}
890907
default:
891908
{
892909
WalkDeclaration(D);

tests/CSharp/CSharpTemplates.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,23 @@ template class DLL_API TemplateWithIndexer<T1>;
474474
template class DLL_API TemplateWithIndexer<T2*>;
475475

476476
class TestForwardedClassInAnotherUnit;
477+
478+
// Forward declaration of class as friend
479+
template<class T> class ForwardTemplateFriendClassContainer;
480+
template<class T> class ForwardTemplateFriendClass;
481+
482+
template<class T>
483+
class ForwardTemplateFriendClassContainer
484+
{
485+
template<class K> friend class ForwardTemplateFriendClass;
486+
};
487+
488+
template<class T>
489+
class ForwardTemplateFriendClass
490+
{
491+
protected:
492+
ForwardTemplateFriendClass() { }
493+
};
494+
495+
class ForwardTemplateFriendClassUser : public ForwardTemplateFriendClass<ForwardTemplateFriendClassUser>
496+
{ };

0 commit comments

Comments
 (0)