mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Bug 568625 - "Invalid arguments" using __underlying_type outside template
ICPPUnaryTypeTransformation was meant to be used only when the transformation is applied on a dependent type. But it was actually always used when creating types for decl specifiers, regardless if a dependent type was involved or not. The untransformed type was causing issues because code dealing with ITypes doesn't apply the transformation everywhere. It seems better to apply the transformation early when possible and let the rest of the logic intact. Change-Id: I1b6d77a857e901f71f00e935e75d24cea87c3118 Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
parent
4a83dbfbdd
commit
c0b26f9993
4 changed files with 31 additions and 8 deletions
|
@ -11382,6 +11382,19 @@ public class AST2CPPTests extends AST2CPPTestBase {
|
||||||
parseAndCheckBindings(getAboveComment(), CPP, true /* use GNU extensions */);
|
parseAndCheckBindings(getAboveComment(), CPP, true /* use GNU extensions */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enum class TestEnum : char {
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void bar(__underlying_type(TestEnum) as) {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// void foo() {
|
||||||
|
// bar('a'); // Invalid arguments 'Candidates are: void bar(@120932903)'
|
||||||
|
// }
|
||||||
|
public void testUnderlyingType_568625() throws Exception {
|
||||||
|
parseAndCheckBindings(getAboveComment(), CPP, true /* use GNU extensions */);
|
||||||
|
}
|
||||||
|
|
||||||
// void ptrFunc(void*);
|
// void ptrFunc(void*);
|
||||||
// void intFunc(int);
|
// void intFunc(int);
|
||||||
// void foo(int* pi, unsigned i) {
|
// void foo(int* pi, unsigned i) {
|
||||||
|
@ -13636,6 +13649,7 @@ public class AST2CPPTests extends AST2CPPTestBase {
|
||||||
// Test<__is_same(Enum, Enum)>::true_val;
|
// Test<__is_same(Enum, Enum)>::true_val;
|
||||||
// Test<__is_same(Enum, int)>::false_val;
|
// Test<__is_same(Enum, int)>::false_val;
|
||||||
// Test<__is_same(EnumChar, char)>::false_val;
|
// Test<__is_same(EnumChar, char)>::false_val;
|
||||||
|
// Test<__is_same(__underlying_type(EnumChar), char)>::true_val;
|
||||||
//
|
//
|
||||||
// Test<TemplateArgs<int, bool>::Value>::false_val;
|
// Test<TemplateArgs<int, bool>::Value>::false_val;
|
||||||
// Test<TemplateArgs<int, int>::Value>::true_val;
|
// Test<TemplateArgs<int, int>::Value>::true_val;
|
||||||
|
|
|
@ -1717,12 +1717,7 @@ public class CPPTemplates {
|
||||||
if (type instanceof ICPPUnaryTypeTransformation) {
|
if (type instanceof ICPPUnaryTypeTransformation) {
|
||||||
ICPPUnaryTypeTransformation typeTransformation = (ICPPUnaryTypeTransformation) type;
|
ICPPUnaryTypeTransformation typeTransformation = (ICPPUnaryTypeTransformation) type;
|
||||||
IType operand = instantiateType(typeTransformation.getOperand(), context);
|
IType operand = instantiateType(typeTransformation.getOperand(), context);
|
||||||
switch (typeTransformation.getOperator()) {
|
return SemanticUtil.applyTypeTransformation(typeTransformation.getOperator(), operand);
|
||||||
case underlying_type:
|
|
||||||
return TypeTraits.underlyingType(operand);
|
|
||||||
default:
|
|
||||||
return null; // shouldn't happen
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type instanceof CPPClosureType) {
|
if (type instanceof CPPClosureType) {
|
||||||
|
|
|
@ -236,7 +236,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnaryTypeTransformation;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownTypeScope;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownTypeScope;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariableTemplate;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariableTemplate;
|
||||||
|
@ -2793,7 +2792,12 @@ public class CPPVisitor extends ASTQueries {
|
||||||
name = ((IASTEnumerationSpecifier) declSpec).getName();
|
name = ((IASTEnumerationSpecifier) declSpec).getName();
|
||||||
} else if (declSpec instanceof ICPPASTTypeTransformationSpecifier) {
|
} else if (declSpec instanceof ICPPASTTypeTransformationSpecifier) {
|
||||||
ICPPASTTypeTransformationSpecifier spec = (ICPPASTTypeTransformationSpecifier) declSpec;
|
ICPPASTTypeTransformationSpecifier spec = (ICPPASTTypeTransformationSpecifier) declSpec;
|
||||||
return new CPPUnaryTypeTransformation(spec.getOperator(), createType(spec.getOperand()));
|
IType type = SemanticUtil.applyTypeTransformation(spec.getOperator(), createType(spec.getOperand()));
|
||||||
|
if (type != null)
|
||||||
|
return type;
|
||||||
|
|
||||||
|
return ProblemType.UNRESOLVED_NAME;
|
||||||
|
|
||||||
} else if (declSpec instanceof ICPPASTSimpleDeclSpecifier) {
|
} else if (declSpec instanceof ICPPASTSimpleDeclSpecifier) {
|
||||||
ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec;
|
ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec;
|
||||||
// Check for decltype(expr)
|
// Check for decltype(expr)
|
||||||
|
|
|
@ -68,6 +68,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
import org.eclipse.cdt.core.parser.Keywords;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
|
@ -945,4 +946,13 @@ public class SemanticUtil {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IType applyTypeTransformation(ICPPUnaryTypeTransformation.Operator operator, IType type) {
|
||||||
|
switch (operator) {
|
||||||
|
case underlying_type:
|
||||||
|
return TypeTraits.underlyingType(type);
|
||||||
|
default:
|
||||||
|
return null; // shouldn't happen
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue