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 6acd173081a..ee230a823f3 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 @@ -187,23 +187,48 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase { validateProblem(0, IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST, null); } - // #ifdef 0 + // /**/ #if 0 + // bug + // /**/ #endif + // passed + // + // /* + // */ #if 0 + // bug + // /**/ #endif + // passed + // + // #if 0 // /**/ #else // OK1 // #endif - // #ifdef 0 - // a /* + // + // #if 0 + // /* // */ #else // OK2 // #endif - // #ifdef 0 + // + // #if 0 // a /**/ #else - // NOTOK + // bug // #endif + // passed + // + // #if 0 + // a /* + // */ #else // interesting, gcc ignores this directive, we mimic the behavior + // bug + // #endif + // passed public void testCommentBeforeDirective_Bug255318() throws Exception { initializeScanner(); + validateIdentifier("passed"); + validateIdentifier("passed"); validateIdentifier("OK1"); validateIdentifier("OK2"); + validateIdentifier("passed"); + validateIdentifier("passed"); validateEOF(); validateProblemCount(0); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java index 8b36ddb7c21..b7ea1359146 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java @@ -99,9 +99,13 @@ public abstract class PreprocessorTestsBase extends BaseTestCase { } protected void validateToken(int tokenType, String image) throws Exception { - IToken t= fScanner.nextToken(); - assertEquals(tokenType, t.getType()); - assertEquals(image, t.getImage()); + try { + IToken t= fScanner.nextToken(); + assertEquals(tokenType, t.getType()); + assertEquals(image, t.getImage()); + } catch (EndOfFileException e) { + fail("Missing token " + image); + } } protected void validateInteger(String expectedImage) throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java index fd38d974bc7..33afb5d59cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java @@ -269,6 +269,7 @@ final public class Lexer { continue; case '*': blockComment(start, '*'); + haveNL= hadNL; continue; case '%': if (fOptions.fSupportSlashPercentComments) {