diff options
2 files changed, 27 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 02fc18b3c28..5c1f393c9d2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -121,6 +121,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -7516,4 +7517,26 @@ public class AST2Tests extends AST2TestBase { public void testOctalFloatingPointLiteral_394048() throws Exception { parseAndCheckBindings(); } + + public void testMacOS9LineEnding_151329a() throws Exception { + parseAndCheckBindings("int waldo;\r#define bar"); + } + + public void testMaxOS9LineEnding_151329b() throws Exception { + // This tests that if there is an \r\n in a macro continuation, + // the \r is not treated as an extra newline. The code + // stringifies the macro expansion and arranges for the string + // length to show up in a template parameter, whose value is + // checked by the test. + String code = "#define MACRO foo\\\r\n" + + "bar\r\n" + + "#define STRINGIFY_(x) #x\r\n" + + "#define STRINGIFY(x) STRINGIFY_(x)\r\n" + + "template <int N> void f(const char (&)[N]);\r\n" + + "int main() { f(STRINGIFY(MACRO)); }\r\n"; + BindingAssertionHelper helper = new BindingAssertionHelper(code, true); + ICPPTemplateInstance f = helper.assertNonProblem("f(STRINGIFY", "f"); + // 7 characters for "foobar" + the null terminator. + assertEquals(7, f.getTemplateArguments()[0].getNonTypeValue().numericalValue().longValue()); + } } 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 90c2925af9f..96c8e66469b 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 @@ -1045,14 +1045,16 @@ final public class Lexer implements ITokenSequence { fEndOffset= ++pos; fCharPhase3= c; switch (c) { - // windows line-ending case '\r': + // windows line-ending if (fInput.get(pos) == '\n') { fEndOffset= pos+1; fCharPhase3= '\n'; return '\n'; } - return c; + // mac os 9 line ending + fCharPhase3= '\n'; + return '\n'; // trigraph sequences case '?': |