mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 10:45:37 +02:00
Bug 480648 - Implement DR 1473
This allows user-defined literal operator definitions with no space between the "" and the identifier. Change-Id: I1233a2a6554b9baf82a4e91d60f603453fe06a04 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
5b532b0fd2
commit
ff6a07a124
2 changed files with 23 additions and 10 deletions
|
@ -11558,13 +11558,10 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
}
|
||||
|
||||
// // Test name lacking a space
|
||||
// int operator ""X(const char* s) { return 0; }
|
||||
// int operator ""_X(const char* s) { return 0; }
|
||||
public void testUserDefinedLiteralNoWhiteSpace1() throws Exception {
|
||||
IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, false);
|
||||
IASTDeclaration decl = tu.getDeclarations()[0];
|
||||
|
||||
assertTrue(decl instanceof IASTProblemDeclaration);
|
||||
assertEquals(IProblem.SYNTAX_ERROR, ((IASTProblemDeclaration)decl).getProblem().getID());
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// // Test literals with spaces before the suffix
|
||||
|
|
|
@ -851,6 +851,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
op= OverloadableOperator.SHIFTR;
|
||||
break;
|
||||
case IToken.tSTRING: // User defined literal T operator "" SUFFIX
|
||||
{
|
||||
IToken strOp = consume();
|
||||
|
||||
// Should be an empty string
|
||||
|
@ -859,11 +860,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
IToken ident = consume(IToken.tIDENTIFIER);
|
||||
|
||||
// Make sure there is at least one white space
|
||||
if (ident.getOffset() <= endOffset) {
|
||||
break;
|
||||
}
|
||||
|
||||
char[] operatorName = CharArrayUtils.concat(firstToken.getCharImage(), " ".toCharArray()); //$NON-NLS-1$
|
||||
operatorName = CharArrayUtils.concat(operatorName, strOp.getCharImage());
|
||||
operatorName = CharArrayUtils.concat(operatorName, ident.getCharImage());
|
||||
|
@ -873,6 +869,26 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IToken.tUSER_DEFINED_STRING_LITERAL: // User defined literal T operator ""SUFFIX
|
||||
{
|
||||
IToken strOp = consume();
|
||||
String image = strOp.getImage();
|
||||
int startQuote = image.indexOf('"');
|
||||
int endQuote = image.lastIndexOf('"');
|
||||
if (startQuote != -1 && endQuote == startQuote + 1) {
|
||||
char[] ident = image.substring(endQuote + 1).toCharArray();
|
||||
|
||||
char[] operatorName = CharArrayUtils.concat(firstToken.getCharImage(), " ".toCharArray()); //$NON-NLS-1$
|
||||
operatorName = CharArrayUtils.concat(operatorName, strOp.getCharImage());
|
||||
operatorName = CharArrayUtils.concat(operatorName, ident);
|
||||
|
||||
IASTName name = getNodeFactory().newOperatorName(operatorName);
|
||||
setRange(name, firstToken.getOffset(), strOp.getEndOffset());
|
||||
return name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
op= OverloadableOperator.valueOf(LA(1));
|
||||
if (op != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue