mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 16:05:25 +02:00
Bug 270892, wide string literals have wrong type
This commit is contained in:
parent
32896c6f39
commit
c8a87c8e6d
2 changed files with 30 additions and 3 deletions
|
@ -7086,4 +7086,27 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||||
ba.assertProblem("test(c)", 4);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,19 +98,23 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
|
||||||
case lk_false:
|
case lk_false:
|
||||||
return new CPPBasicType(ICPPBasicType.t_bool, 0, this);
|
return new CPPBasicType(ICPPBasicType.t_bool, 0, this);
|
||||||
case lk_char_constant:
|
case lk_char_constant:
|
||||||
return new CPPBasicType(IBasicType.t_char, 0, this);
|
return new CPPBasicType(getCharType(), 0, this);
|
||||||
case lk_float_constant:
|
case lk_float_constant:
|
||||||
return classifyTypeOfFloatLiteral();
|
return classifyTypeOfFloatLiteral();
|
||||||
case lk_integer_constant:
|
case lk_integer_constant:
|
||||||
return classifyTypeOfIntLiteral();
|
return classifyTypeOfIntLiteral();
|
||||||
case lk_string_literal:
|
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);
|
type = new CPPQualifierType(type, true, false);
|
||||||
return new CPPArrayType(type);
|
return new CPPArrayType(type);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCharType() {
|
||||||
|
return getValue()[0] == 'L' ? ICPPBasicType.t_wchar_t : IBasicType.t_char;
|
||||||
|
}
|
||||||
|
|
||||||
private IType classifyTypeOfFloatLiteral() {
|
private IType classifyTypeOfFloatLiteral() {
|
||||||
final char[] lit= getValue();
|
final char[] lit= getValue();
|
||||||
final int len= lit.length;
|
final int len= lit.length;
|
||||||
|
|
Loading…
Add table
Reference in a new issue