mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 13:25:45 +02:00
75482: Friendship erroneously granted
This commit is contained in:
parent
37d7c2e939
commit
dc2c9cec11
2 changed files with 21 additions and 3 deletions
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
package org.eclipse.cdt.core.parser.tests;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
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.IASTBaseSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
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.IASTEnumerationSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||||
|
@ -352,4 +355,19 @@ public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest {
|
||||||
IASTUsingDeclaration using = (IASTUsingDeclaration) i.next();
|
IASTUsingDeclaration using = (IASTUsingDeclaration) i.next();
|
||||||
assertFalse( i.hasNext() );
|
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() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3236,7 +3236,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
ISymbol checkSymbol = null;
|
ISymbol checkSymbol = null;
|
||||||
if (!isTemplateId) {
|
if (!isTemplateId) {
|
||||||
try {
|
try {
|
||||||
if (isFriend) {
|
if (isFriend && isForewardDecl) {
|
||||||
checkSymbol = ((IDerivableContainerSymbol) currentScopeSymbol)
|
checkSymbol = ((IDerivableContainerSymbol) currentScopeSymbol)
|
||||||
.lookupForFriendship(newSymbolName);
|
.lookupForFriendship(newSymbolName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3275,7 +3275,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
pstType);
|
pstType);
|
||||||
checkSymbol.setIsForwardDeclaration(true);
|
checkSymbol.setIsForwardDeclaration(true);
|
||||||
try {
|
try {
|
||||||
if (isFriend) {
|
if (isFriend && isForewardDecl) {
|
||||||
((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol);
|
((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol);
|
||||||
} else {
|
} else {
|
||||||
if (!isTemplateId)
|
if (!isTemplateId)
|
||||||
|
@ -3296,7 +3296,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
references, isForewardDecl, filename);
|
references, isForewardDecl, filename);
|
||||||
attachSymbolExtension(checkSymbol, elab, !isForewardDecl);
|
attachSymbolExtension(checkSymbol, elab, !isForewardDecl);
|
||||||
return elab;
|
return elab;
|
||||||
} else if (isFriend) {
|
} else if (isFriend && isForewardDecl) {
|
||||||
((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol);
|
((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol);
|
||||||
}
|
}
|
||||||
if (checkSymbol != null) {
|
if (checkSymbol != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue