1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

User defined operators are considered only for user-defined types, bug 291409.

This commit is contained in:
Markus Schorn 2009-10-06 12:09:24 +00:00
parent 1c2270f0cb
commit 164d59a0d8
3 changed files with 28 additions and 4 deletions

View file

@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -7432,5 +7433,24 @@ public class AST2CPPTests extends AST2BaseTest {
T= bh.assertNonProblem("T* m2", 1);
assertSame(X, T.getOwner());
}
// class ULONGLONG {
// public :
// ULONGLONG (unsigned long long val) {}
// friend ULONGLONG operator ~ ( const ULONGLONG & ) { return 0; }
// };
//
// int main() {
// return ~0;
// }
public void testNonUserdefinedOperator_Bug291409_2() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.CPP);
IASTFunctionDefinition def= getDeclaration(tu, 1);
IASTReturnStatement rstmt= getStatement(def, 0);
IASTImplicitNameOwner expr= (IASTImplicitNameOwner) rstmt.getReturnValue();
assertEquals(0, expr.getImplicitNames().length);
}
}

View file

@ -161,7 +161,7 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres
return overload;
overload = CPPSemantics.findOverloadedOperator(this);
if(operand != null && op == op_amper && computePointerToMemberType() instanceof CPPPointerToMemberType)
if(overload != null && op == op_amper && computePointerToMemberType() instanceof CPPPointerToMemberType)
overload = null;
return overload;

View file

@ -2642,7 +2642,9 @@ public class CPPSemantics {
IType type = exp.getOperand().getExpressionType();
type = SemanticUtil.getNestedType(type, TDEF | REF | CVQ);
if (!isUserDefined(type))
return null;
return findOverloadedOperator(exp, args, type, op.toCharArray(), true);
}
@ -2659,8 +2661,10 @@ public class CPPSemantics {
IType op2type = SemanticUtil.getUltimateTypeUptoPointers(exp.getOperand2().getExpressionType());
if (op2type instanceof IProblemBinding)
return null;
if (isUserDefined(op1type) || isUserDefined(op2type))
lookupNonMember = true;
if (!isUserDefined(op1type) && !isUserDefined(op2type))
return null;
lookupNonMember= true;
}
return findOverloadedOperator(exp, args, op1type, op.toCharArray(), lookupNonMember);