1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

186736: add fix and regression test for case where the lhs of the operator is a pointer, and overloads should not be searched

This commit is contained in:
Andrew Ferguson 2007-06-05 09:07:18 +00:00
parent d585f679d7
commit d4e0d5c793
10 changed files with 253 additions and 2 deletions

View file

@ -3791,6 +3791,30 @@ public class AST2Tests extends AST2BaseTest {
assertEquals("AA", ((ICPPMethod)methodAA).getClassOwner().getName());
}
// class B {
// public:
// void bar() {}
// };
// class A {
// public:
// B* operator->() { return new B(); }
// void foo() {}
// };
//
// void main() {
// A a, &aa=a, *ap= new A();
// a.foo();
// ap->foo();
// aa.foo();
// (*ap)->bar();
// (&aa)->foo();
// (&a)->foo();
// }
public void test186736_variant2() throws Exception {
StringBuffer buffer = getContents(1)[0];
IASTTranslationUnit tu= parseAndCheckBindings(buffer.toString(), ParserLanguage.CPP);
}
// typedef int int32;
// int32 f(int32 (*p)) {
// return *p;

View file

@ -369,7 +369,7 @@ public class CPPSemantics {
{
ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempName.getParent();
implied = CPPVisitor.getExpressionType( fieldRef.getFieldOwner() );
IType ultimateImplied= getUltimateType(implied, true);
IType ultimateImplied= getUltimateTypeUptoPointers(implied);
if( prop != STRING_LOOKUP_PROPERTY && fieldRef.isPointerDereference() && ultimateImplied instanceof ICPPClassType) {
ICPPFunction operator= findOperator(fieldRef, (ICPPClassType) ultimateImplied);
try {
@ -2891,6 +2891,29 @@ public class CPPSemantics {
}
}
/**
* Descends into type containers, stopping at pointer or
* pointer-to-member types.
* @param type
* @return the ultimate type contained inside the specified type
*/
public static IType getUltimateTypeUptoPointers(IType type){
try {
while( true ){
if( type instanceof ITypedef )
type = ((ITypedef)type).getType();
else if( type instanceof IQualifierType )
type = ((IQualifierType)type).getType();
else if( type instanceof ICPPReferenceType )
type = ((ICPPReferenceType)type).getType();
else
return type;
}
} catch ( DOMException e ) {
return e.getProblem();
}
}
static private boolean isCompleteType( IType type ){
type = getUltimateType( type, false );
if( type instanceof ICPPClassType && type instanceof ICPPInternalBinding )

View file

@ -863,7 +863,7 @@ public class CPPVisitor {
IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner();
IType type = getExpressionType( owner );
if( ((ICPPASTFieldReference)parent).isPointerDereference() ){
type= CPPSemantics.getUltimateType(type, true);
type= CPPSemantics.getUltimateTypeUptoPointers(type);
if( type instanceof ICPPClassType ){
ICPPFunction op = CPPSemantics.findOperator( (IASTFieldReference)parent, (ICPPClassType) type );
if( op != null ){

View file

@ -68,3 +68,5 @@ namespace xNamespace {
void xNamespaceFunction(){
}
};

View file

@ -0,0 +1,9 @@
#include "CompletionTestStart41.h"
void main() {
A a, &aa=a, *ap= new A();
a.foo();
ap->
}
// end

View file

@ -0,0 +1,11 @@
class B {
public:
void bar() {}
};
class A {
public:
B* operator->() { return new B(); }
void foo() {}
};

View file

@ -0,0 +1,9 @@
#include "CompletionTestStart41.h"
void main() {
A a, &aa=a, *ap= new A();
a.foo();
a->
}
// end

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Symbian - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Test operator is followed during member reference
*/
public class CompletionTest_MemberReference_Arrow_NoPrefix2 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart41.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart41.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "";
private final String[] expectedResults = {
"A", "foo(void) void",
"operator ->(void) B *"
};
public CompletionTest_MemberReference_Arrow_NoPrefix2(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_MemberReference_Arrow_NoPrefix2.class.getName());
suite.addTest(new CompletionTest_MemberReference_Arrow_NoPrefix2("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" ap-> ") + 5;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Symbian - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Testing operator is not followed on pointer to class with overloaded operator ->
*/
public class CompletionTest_MemberReference_Arrow_NoPrefix3 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart42.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart41.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "";
private final String[] expectedResults = {
"B", "bar(void) void"
};
public CompletionTest_MemberReference_Arrow_NoPrefix3(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_MemberReference_Arrow_NoPrefix3.class.getName());
suite.addTest(new CompletionTest_MemberReference_Arrow_NoPrefix3("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf("a->")+3;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -42,6 +42,8 @@ public class ContentAssist2TestSuite extends TestSuite {
addTest(CompletionTest_MacroRef_NoPrefix.suite());
addTest(CompletionTest_MacroRef_Prefix.suite());
addTest(CompletionTest_MemberReference_Arrow_NoPrefix.suite());
addTest(CompletionTest_MemberReference_Arrow_NoPrefix2.suite());
addTest(CompletionTest_MemberReference_Arrow_NoPrefix3.suite());
addTest(CompletionTest_MemberReference_Arrow_Prefix.suite());
addTest(CompletionTest_MemberReference_Arrow_Prefix2.suite());
addTest(CompletionTest_MemberReference_Dot_NoPrefix.suite());