]> granicus.if.org Git - clang/commitdiff
Fix PR 19630, don't crash when file ends with whitespace.
authorRichard Trieu <rtrieu@google.com>
Fri, 2 May 2014 23:40:32 +0000 (23:40 +0000)
committerRichard Trieu <rtrieu@google.com>
Fri, 2 May 2014 23:40:32 +0000 (23:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207883 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
test/Parser/eof.cpp [new file with mode: 0644]

index 07e606c98640023e9822e213dca78d0f1336c525..379beafbcea4535402409751a236e896bc22f8af 100644 (file)
@@ -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 (file)
index 0000000..3c966c5
--- /dev/null
@@ -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