1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 03:15:33 +02:00

75482: Friendship erroneously granted

This commit is contained in:
Andrew Niefer 2004-10-07 18:13:20 +00:00
parent 37d7c2e939
commit dc2c9cec11
2 changed files with 21 additions and 3 deletions

View file

@ -6,6 +6,8 @@
*/
package org.eclipse.cdt.core.parser.tests;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.NoSuchElementException;
@ -22,6 +24,7 @@ import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.ast.IASTField;
@ -352,4 +355,19 @@ public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest {
IASTUsingDeclaration using = (IASTUsingDeclaration) i.next();
assertFalse( i.hasNext() );
}
public void testBug75482() throws Exception{
Writer writer = new StringWriter();
writer.write( "class A { friend class B * helper(); };" ); //$NON-NLS-1$
Iterator i = parse( writer.toString() ).getDeclarations();
IASTClassSpecifier A = (IASTClassSpecifier) i.next();
IASTFunction helper = (IASTFunction) i.next();
i = A.getDeclarations();
IASTElaboratedTypeSpecifier B = (IASTElaboratedTypeSpecifier) i.next();
assertFalse( i.hasNext() );
i = A.getFriends();
assertEquals( i.next(), helper );
assertFalse( i.hasNext() );
}
}

View file

@ -3236,7 +3236,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ISymbol checkSymbol = null;
if (!isTemplateId) {
try {
if (isFriend) {
if (isFriend && isForewardDecl) {
checkSymbol = ((IDerivableContainerSymbol) currentScopeSymbol)
.lookupForFriendship(newSymbolName);
} else {
@ -3275,7 +3275,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
pstType);
checkSymbol.setIsForwardDeclaration(true);
try {
if (isFriend) {
if (isFriend && isForewardDecl) {
((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol);
} else {
if (!isTemplateId)
@ -3296,7 +3296,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
references, isForewardDecl, filename);
attachSymbolExtension(checkSymbol, elab, !isForewardDecl);
return elab;
} else if (isFriend) {
} else if (isFriend && isForewardDecl) {
((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol);
}
if (checkSymbol != null) {