diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java index e6ed8b24c7d..58c8766127e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java @@ -149,4 +149,20 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase { validateEOF(); validateProblemCount(0); } + + // #if if + // no + // #else + // yes + // #endif + // #if or + // no + // #endif + public void testKeywordsInConditionalExpression_Bug246369() throws Exception { + initializeScanner(); + validateIdentifier("yes"); + validateEOF(); + validateProblemCount(1); + validateProblem(0, IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, null); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java index 3cf380f0458..614c5281f8f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java @@ -257,7 +257,27 @@ class ExpressionEvaluator { case IToken.tIDENTIFIER: consume(); return 0; + // 16.1.4 alternate keywords are not replaced by a 0 + case IToken.tAND: + case IToken.tOR: + case IToken.tBITOR: + case IToken.tBITORASSIGN: + case IToken.tXOR: + case IToken.tXORASSIGN: + case IToken.tAMPER: + case IToken.tAMPERASSIGN: + case IToken.tSTRING: + case IToken.tLSTRING: + throw new EvalException(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, null); + default: + // 16.1.4 keywords are replaced by 0 + final char[] image= fTokens.getCharImage(); + if (image.length > 0) { + final char c= image[0]; + if ((c>='a' && c<='z') || (c>='A' && c<='Z') || c == '_' || c=='$' || c=='@') + return 0; + } throw new EvalException(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, null); } }