1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Bug 526724: corrected deduced type for string literals with u8 prefix

Change-Id: Ibc55f6cbd8f425149598b397a4d2fb90b7ed6b8b
Signed-off-by: Marco Syfrig <marco.syfrig@gmail.com>
This commit is contained in:
Marco Syfrig 2017-11-07 04:14:21 +01:00
parent 69404fdf89
commit 9a9e80e115
2 changed files with 50 additions and 9 deletions

View file

@ -76,6 +76,7 @@ import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -147,6 +148,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
@ -7607,6 +7609,37 @@ public class AST2CPPTests extends AST2CPPTestBase {
assertSame(col.getName(4).resolveBinding(), col.getName(11).resolveBinding());
assertSame(col.getName(6).resolveBinding(), col.getName(12).resolveBinding());
}
// auto L = L"";
// auto u8 = u8"";
// auto u = u"";
// auto U = U"";
public void testStringLiteralPrefixTypes_526724() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), CPP);
NameCollector col = new NameCollector();
tu.accept(col);
IType actual_L = ((IVariable) col.getName(0).resolveBinding()).getType();
IType actual_u8 = ((IVariable) col.getName(1).resolveBinding()).getType();
IType actual_u = ((IVariable) col.getName(2).resolveBinding()).getType();
IType actual_U = ((IVariable) col.getName(3).resolveBinding()).getType();
IType eWChar = createStringType(Kind.eWChar);
IType eChar = createStringType(Kind.eChar);
IType eChar16 = createStringType(Kind.eChar16);
IType eChar32 = createStringType(Kind.eChar32);
assertSameType(actual_L, eWChar);
assertSameType(actual_u8, eChar);
assertSameType(actual_u, eChar16);
assertSameType(actual_U, eChar32);
}
protected IType createStringType(Kind kind) {
IType type = new CPPBasicType(kind, 0);
type = new CPPQualifierType(type, true, false);
return new CPPPointerType(type);
}
// namespace ns {
// struct A {};

View file

@ -242,6 +242,10 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
// Skip past a prefix affecting the character type.
if (fValue[0] == 'L' || fValue[0] == 'u' || fValue[0] == 'U') {
if(fValue[1] == '8') {
++start;
}
++start;
}
@ -347,15 +351,19 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
public Kind getBasicCharKind() {
switch (fValue[0]) {
case 'L':
return Kind.eWChar;
case 'u':
return Kind.eChar16;
case 'U':
return Kind.eChar32;
default:
return Kind.eChar;
}
case 'L':
return Kind.eWChar;
case 'U':
return Kind.eChar32;
case 'u':
// Bug 526724 u8 should result in Kind.eChar
if (fValue[1] != '8') {
return Kind.eChar16;
}
//$FALL-THROUGH$
default:
return Kind.eChar;
}
}
private IType classifyTypeOfFloatLiteral() {