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

Bug 270892, wide string literals have wrong type

This commit is contained in:
Mike Kucera 2009-04-01 21:56:45 +00:00
parent 32896c6f39
commit c8a87c8e6d
2 changed files with 30 additions and 3 deletions

View file

@ -7085,5 +7085,28 @@ public class AST2CPPTests extends AST2BaseTest {
public void testInvalidUserDefinedConversion_Bug269729() throws Exception {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ba.assertProblem("test(c)", 4);
}
}
// int foo(char * x);
// int foo(wchar_t * x);
// int foo(char x);
// int foo(wchar_t x);
//
// int main() {
// foo("asdf");
// foo(L"asdf");
// foo('a');
// foo(L'a');
// }
public void testWideCharacterLiteralTypes_Bug270892() throws Exception {
IASTTranslationUnit tu = parse( getAboveComment(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertSame(col.getName(0).resolveBinding(), col.getName(9).resolveBinding());
assertSame(col.getName(2).resolveBinding(), col.getName(10).resolveBinding());
assertSame(col.getName(4).resolveBinding(), col.getName(11).resolveBinding());
assertSame(col.getName(6).resolveBinding(), col.getName(12).resolveBinding());
}
}

View file

@ -98,19 +98,23 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
case lk_false:
return new CPPBasicType(ICPPBasicType.t_bool, 0, this);
case lk_char_constant:
return new CPPBasicType(IBasicType.t_char, 0, this);
return new CPPBasicType(getCharType(), 0, this);
case lk_float_constant:
return classifyTypeOfFloatLiteral();
case lk_integer_constant:
return classifyTypeOfIntLiteral();
case lk_string_literal:
IType type = new CPPBasicType(IBasicType.t_char, 0, this);
IType type = new CPPBasicType(getCharType(), 0, this);
type = new CPPQualifierType(type, true, false);
return new CPPArrayType(type);
}
return null;
}
private int getCharType() {
return getValue()[0] == 'L' ? ICPPBasicType.t_wchar_t : IBasicType.t_char;
}
private IType classifyTypeOfFloatLiteral() {
final char[] lit= getValue();
final int len= lit.length;