From: Richard Trieu Date: Fri, 2 May 2014 23:40:32 +0000 (+0000) Subject: Fix PR 19630, don't crash when file ends with whitespace. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cdc03fcb19b503b108306f645c8b11cfccad65d;p=clang Fix PR 19630, don't crash when file ends with whitespace. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207883 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 07e606c986..379beafbce 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4834,7 +4834,8 @@ void Parser::ParseDirectDeclarator(Declarator &D) { LLVM_BUILTIN_TRAP; if (D.getContext() == Declarator::MemberContext) Diag(Tok, diag::err_expected_member_name_or_semi) - << D.getDeclSpec().getSourceRange(); + << (D.getDeclSpec().isEmpty() ? SourceRange() + : D.getDeclSpec().getSourceRange()); else if (getLangOpts().CPlusPlus) { if (Tok.is(tok::period) || Tok.is(tok::arrow)) Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow); diff --git a/test/Parser/eof.cpp b/test/Parser/eof.cpp new file mode 100644 index 0000000000..3c966c50e1 --- /dev/null +++ b/test/Parser/eof.cpp @@ -0,0 +1,13 @@ +// RUN: not %clang_cc1 %s -fsyntax-only 2>&1 | FileCheck %s + +// CHECK: error: expected member name or ';' after declaration specifiers +// CHECK: error: expected '}' +// CHECK: note: to match this '{' +// CHECK: error: expected ';' after class +// CHECK: error: anonymous structs and classes must be class members +// CHECK: 4 errors generated. + +// Do not add anything to the end of this file. This requires the whitespace +// plus EOF after the template keyword. + +class { template