mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-14 03:35:37 +02:00
Fix for 181942, parsing 'char x= *"a";'
This commit is contained in:
parent
d0407f36ab
commit
d70bbc8768
3 changed files with 19 additions and 13 deletions
|
@ -3640,9 +3640,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void test() {
|
// void test() {
|
||||||
// const char d= *"b";
|
// char d= *"b";
|
||||||
// }
|
// }
|
||||||
public void _testBug181942() throws Exception {
|
public void testBug181942() throws Exception {
|
||||||
StringBuffer buffer = getContents(1)[0];
|
StringBuffer buffer = getContents(1)[0];
|
||||||
for (int i = 0; i < LANGUAGES.length; i++)
|
for (int i = 0; i < LANGUAGES.length; i++)
|
||||||
parse( buffer.toString(), LANGUAGES[i], true, true );
|
parse( buffer.toString(), LANGUAGES[i], true, true );
|
||||||
|
|
|
@ -2910,11 +2910,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
int offset = consume().getOffset();
|
int offset = consume().getOffset();
|
||||||
IASTExpression castExpression = castExpression();
|
IASTExpression castExpression = castExpression();
|
||||||
if( castExpression instanceof IASTLiteralExpression && ( operator == IASTUnaryExpression.op_amper || operator == IASTUnaryExpression.op_star ) )
|
if( castExpression instanceof IASTLiteralExpression ) {
|
||||||
|
IASTLiteralExpression lit= (IASTLiteralExpression) castExpression;
|
||||||
|
if ( operator == IASTUnaryExpression.op_amper ||
|
||||||
|
(operator == IASTUnaryExpression.op_star && lit.getKind() != IASTLiteralExpression.lk_string_literal) )
|
||||||
{
|
{
|
||||||
backup( mark );
|
backup( mark );
|
||||||
throwBacktrack( mark );
|
throwBacktrack( mark );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return buildUnaryExpression(operator, castExpression, offset,
|
return buildUnaryExpression(operator, castExpression, offset,
|
||||||
calculateEndOffset(castExpression));
|
calculateEndOffset(castExpression));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5460,15 +5460,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
int offset = consume().getOffset();
|
int offset = consume().getOffset();
|
||||||
IASTExpression castExpression = castExpression();
|
IASTExpression castExpression = castExpression();
|
||||||
if( castExpression instanceof IASTLiteralExpression && ( operator == IASTUnaryExpression.op_amper || operator == IASTUnaryExpression.op_star ) )
|
if (castExpression instanceof IASTLiteralExpression) {
|
||||||
{
|
|
||||||
IASTLiteralExpression literal = (IASTLiteralExpression) castExpression;
|
IASTLiteralExpression literal = (IASTLiteralExpression) castExpression;
|
||||||
if( literal.getKind() != ICPPASTLiteralExpression.lk_this )
|
if( literal.getKind() != ICPPASTLiteralExpression.lk_this ) {
|
||||||
{
|
if ( operator == IASTUnaryExpression.op_amper ||
|
||||||
|
(operator == IASTUnaryExpression.op_star &&
|
||||||
|
literal.getKind() != IASTLiteralExpression.lk_string_literal) ) {
|
||||||
backup( mark );
|
backup( mark );
|
||||||
throwBacktrack( mark );
|
throwBacktrack( mark );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return buildUnaryExpression(operator, castExpression, offset,
|
return buildUnaryExpression(operator, castExpression, offset,
|
||||||
calculateEndOffset(castExpression));
|
calculateEndOffset(castExpression));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue