Skip to content

Commit

Permalink
Merge 9b9bf47 into 3185b28
Browse files Browse the repository at this point in the history
  • Loading branch information
drichardson committed Apr 1, 2021
2 parents 3185b28 + 9b9bf47 commit 6dd35ca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--kinds-C++=m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p input.cpp /^ Class *p;$/;" m class:A typeref:typename:Class * file:
a_c_forward input.cpp /^ A<class C> a_c_forward;$/;" m class:B typeref:typename:A<class C> file:
a_s_forward input.cpp /^ A<struct S> a_s_forward;$/;" m class:B typeref:typename:A<struct S> file:
a_u_forward input.cpp /^ A<union U> a_u_forward;$/;" m class:B typeref:typename:A<union U> file:
16 changes: 16 additions & 0 deletions Units/parser-cxx.r/template-member-forward-declaration.d/input.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
template <class Class>
class A
{
public:
A() { p = new Class(); }
Class *p;
};

class B {
public:
// forward declaration okay because only used as pointer in Template
A<class C> a_c_forward;
A<struct S> a_s_forward;
A<union U> a_u_forward;
};

16 changes: 13 additions & 3 deletions parsers/cxx/cxx_parser_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
cppBeginStatement();
}

int iNestedAngleBracketLevel = 0;
for(;;)
{
if(!cxxParserParseNextToken())
Expand Down Expand Up @@ -392,21 +393,24 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
}
break;
case CXXKeywordCLASS:
if(!cxxParserParseClassStructOrUnion(CXXKeywordCLASS,CXXTagCPPKindCLASS,CXXScopeTypeClass))
if(iNestedAngleBracketLevel == 0 &&
!cxxParserParseClassStructOrUnion(CXXKeywordCLASS,CXXTagCPPKindCLASS,CXXScopeTypeClass))
{
CXX_DEBUG_LEAVE_TEXT("Failed to parse class/struct/union");
return false;
}
break;
case CXXKeywordSTRUCT:
if(!cxxParserParseClassStructOrUnion(CXXKeywordSTRUCT,CXXTagKindSTRUCT,CXXScopeTypeStruct))
if(iNestedAngleBracketLevel == 0 &&
!cxxParserParseClassStructOrUnion(CXXKeywordSTRUCT,CXXTagKindSTRUCT,CXXScopeTypeStruct))
{
CXX_DEBUG_LEAVE_TEXT("Failed to parse class/struct/union");
return false;
}
break;
case CXXKeywordUNION:
if(!cxxParserParseClassStructOrUnion(CXXKeywordUNION,CXXTagKindUNION,CXXScopeTypeUnion))
if(iNestedAngleBracketLevel == 0 &&
!cxxParserParseClassStructOrUnion(CXXKeywordUNION,CXXTagKindUNION,CXXScopeTypeUnion))
{
CXX_DEBUG_LEAVE_TEXT("Failed to parse class/struct/union");
return false;
Expand Down Expand Up @@ -744,6 +748,12 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
else if (cxxScopeGetType() == CXXScopeTypeClass)
cxxSubparserUnknownIdentifierInClassNotify(g_cxx.pToken);
break;
case CXXTokenTypeSmallerThanSign:
iNestedAngleBracketLevel++;
break;
case CXXTokenTypeGreaterThanSign:
iNestedAngleBracketLevel--;
break;
default:
// something else we didn't handle
break;
Expand Down

0 comments on commit 6dd35ca

Please sign in to comment.