1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 10:45:37 +02:00

Bug 470014 - Name resolution problem with ref-qualified methods

Fixed signatures of index methods with ref-qualifiers.

Change-Id: I6f49732c6cec273ca7fdb095340e438ca1a508f0
This commit is contained in:
Sergey Prigogin 2015-06-17 20:34:33 -07:00
parent 6839ee074e
commit 4ac73d7e0c
5 changed files with 67 additions and 16 deletions

View file

@ -18,8 +18,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
@ -50,6 +48,8 @@ import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.core.runtime.CoreException;
import junit.framework.TestSuite;
/**
* For testing PDOM binding CPP language resolution
*/
@ -659,6 +659,43 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
assertQNEquals("n1::n2::U", b12);
}
// struct A {
// A& operator<<(int);
// void p() &;
// void p() &&;
// };
// A& operator<<(A&&, char);
// void test() {
// A a;
// A() << 1;//1 // calls A::operator<<(int)
// A() << 'c';//2 // calls operator<<(A&&, char)
// a << 1;//3 // calls A::operator<<(int)
// a << 'c';//4 // calls A::operator<<(int)
// A().p();//5 // calls A::p()&&
// a.p();//6 // calls A::p()&
// }
public void testRankingOfReferenceBindings() throws Exception {
ICPPMethod m= getBindingFromImplicitASTName("<< 1;//1", 2);
assertNotNull(m);
assertEquals(1, m.getType().getParameterTypes().length);
ICPPFunction f= getBindingFromImplicitASTName("<< 'c';//2", 2);
assertNotNull(f);
assertEquals(2, f.getType().getParameterTypes().length);
m= getBindingFromImplicitASTName("<< 1;//3", 2);
assertNotNull(m);
assertEquals(1, m.getType().getParameterTypes().length);
m= getBindingFromImplicitASTName("<< 'c';//4", 2);
assertNotNull(m);
assertEquals(1, m.getType().getParameterTypes().length);
m= getBindingFromFirstIdentifier("p();//5");
assertNotNull(m);
assertTrue(m.getType().isRValueReference());
m= getBindingFromFirstIdentifier("p();//6");
assertNotNull(m);
assertFalse(m.getType().isRValueReference());
}
// // header content
// namespace n1 { namespace n2 { class C {}; } }
// class c1 { public: class c2 { public: class C {}; }; };

View file

@ -64,7 +64,12 @@ import org.eclipse.core.runtime.PlatformObject;
* Binding for C++ function
*/
public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInternalFunction {
public static final ICPPFunction UNINITIALIZED_FUNCTION = new CPPFunction(null);
public static final ICPPFunction UNINITIALIZED_FUNCTION = new CPPFunction(null) {
@Override
public String toString() {
return "UNINITIALIZED_FUNCTION"; //$NON-NLS-1$
}
};
protected IASTDeclarator[] declarations;
protected ICPPASTFunctionDeclarator definition;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2014 IBM Corporation and others.
* Copyright (c) 2004, 2015 IBM Corporation 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
@ -78,7 +78,7 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType {
return false;
}
} else {
if (!SemanticUtil.isEmptyParameterList(parameters)
if (!SemanticUtil.isEmptyParameterList(parameters)
|| !SemanticUtil.isEmptyParameterList(fps)) {
return false;
}
@ -170,11 +170,12 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType {
for (int i = 0; i < pars.length; i++) {
pars[i]= buffer.unmarshalType();
}
return new CPPFunctionType(rt, pars,
(firstBytes & ITypeMarshalBuffer.FLAG1) != 0, // const
(firstBytes & ITypeMarshalBuffer.FLAG3) != 0, // volatile
(firstBytes & ITypeMarshalBuffer.FLAG5) != 0, // has ref-qualifier
(firstBytes & ITypeMarshalBuffer.FLAG4) != 0, // rvalue reference
(firstBytes & ITypeMarshalBuffer.FLAG2) != 0); // takes varargs
boolean isConst = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0;
boolean takesVarargs = (firstBytes & ITypeMarshalBuffer.FLAG2) != 0;
boolean isVolatile = (firstBytes & ITypeMarshalBuffer.FLAG3) != 0;
boolean hasRefQualifier = (firstBytes & ITypeMarshalBuffer.FLAG4) != 0;
boolean isRValueReference = (firstBytes & ITypeMarshalBuffer.FLAG5) != 0;
return new CPPFunctionType(rt, pars, isConst, isVolatile, hasRefQualifier, isRValueReference,
takesVarargs);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2011 QNX Software Systems and others.
* Copyright (c) 2007, 2015 QNX 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
@ -81,6 +81,11 @@ public class IndexCPPSignatureUtil {
buffer.append('c');
if (ft.isVolatile())
buffer.append('v');
if (ft.hasRefQualifier()) {
buffer.append('&');
if (ft.isRValueReference())
buffer.append('&');
}
}
return buffer.toString();

View file

@ -261,11 +261,14 @@ public class PDOM extends PlatformObject implements IPDOM {
*
* CDT 8.7 development (versions not supported on the 8.6.x branch)
* 181.0 - C function type with varargs, bug 452416.
* 182.0 - A flag added to PDOMCPPClassSpecialization, bug 466362.
* 182.0 - A flag added to PDOMCPPClassSpecialization, bug 466362. <<CDT 8.7>>
*
* CDT 8.8 development (versions not supported on the 8.7.x branch)
* 190.0 - Signature change for methods with ref-qualifiers, bug 470014.
*/
private static final int MIN_SUPPORTED_VERSION= version(182, 0);
private static final int MAX_SUPPORTED_VERSION= version(182, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(182, 0);
private static final int MIN_SUPPORTED_VERSION= version(190, 0);
private static final int MAX_SUPPORTED_VERSION= version(190, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(190, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;