1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 562697 - Fix comparison of qualifier type and pointer type

CDT has two representations for a pointer type wrapped in a
qualifier type: it can be an IPointerType with some qualifiers
set on it directly, or an IPointerType wrapped in an
IQualifierType. (We prefer the first representation to avoid
creating too many wrappers, but sometimes the second one arises
during template instantiation.) This patch makes sure that two
such types can compare equal even if they use different
representations.

Change-Id: Ia8c7d227c74378aae74f04545b9a69103c14e74b
This commit is contained in:
Nathan Ridge 2020-05-02 00:38:50 -04:00
parent 7f7c2a0c24
commit 477aa9c798
2 changed files with 24 additions and 1 deletions

View file

@ -13563,4 +13563,15 @@ public class AST2CPPTests extends AST2CPPTestBase {
assertTrue(((ICPPEnumeration) col.getType()).isNoDiscard()); assertTrue(((ICPPEnumeration) col.getType()).isNoDiscard());
assertFalse(((ICPPEnumeration) f.getType()).isNoDiscard()); assertFalse(((ICPPEnumeration) f.getType()).isNoDiscard());
} }
// template <typename T>
// void waldo(const T&) {}
//
// typedef int* IntPtr;
//
// template <>
// void waldo(const IntPtr&) {}
public void testExplicitSpecPointerType_562697() throws Exception {
parseAndCheckBindings();
}
} }

View file

@ -15,12 +15,14 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerializableType { public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerializableType {
@ -38,8 +40,18 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerial
public boolean isSameType(IType o) { public boolean isSameType(IType o) {
if (o instanceof ITypedef) if (o instanceof ITypedef)
return o.isSameType(this); return o.isSameType(this);
if (!(o instanceof IQualifierType)) if (!(o instanceof IQualifierType)) {
// Handle the case where we store the qualifiers in the IPointerType.
if (o instanceof IPointerType) {
IType nested = SemanticUtil.getSimplifiedType(type);
if (nested instanceof IPointerType) {
IPointerType pt = (IPointerType) o;
return isConst() == pt.isConst() && isVolatile() == pt.isVolatile()
&& ((IPointerType) nested).getType().isSameType(pt.getType());
}
}
return false; return false;
}
IQualifierType pt = (IQualifierType) o; IQualifierType pt = (IQualifierType) o;
if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile() && type != null) if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile() && type != null)