aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein.wu@gmail.com>2021-10-12 16:13:09 +0200
committerHaojian Wu <hokein.wu@gmail.com>2021-10-18 10:00:21 +0200
commit6e63f96e11ee9af300b166c994980d3b80cea0c7 (patch)
treead2efe4e7bcb6983c6e7e75da9e43d651c94b903 /clang/lib/Parse/ParseDecl.cpp
parent3f0b178de21ee82791a6ebe198314f14c0287a44 (diff)
downloadllvm-6e63f96e11ee9af300b166c994980d3b80cea0c7.zip
llvm-6e63f96e11ee9af300b166c994980d3b80cea0c7.tar.gz
llvm-6e63f96e11ee9af300b166c994980d3b80cea0c7.tar.bz2
[Parse] Improve diagnostic and recovery when there is an extra override in the outline method definition.
The clang behavior was poor before this patch: ``` void B::foo() override {} // Before: clang emited "expcted function body after function // declarator", and skiped all contents until it hits a ";", the // following function f() is discarded. // VS // Now "override is not allowed" with a remove fixit, and following f() // is retained. void f(); ``` Differential Revision: https://reviews.llvm.org/D111883
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 9f660e4..a087106 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2021,6 +2021,18 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
Actions.CodeCompleteAfterFunctionEquals(D);
return nullptr;
}
+ // We're at the point where the parsing of function declarator is finished.
+ //
+ // A common error is that users accidently add a virtual specifier
+ // (e.g. override) in an out-line method definition.
+ // We attempt to recover by stripping all these specifiers coming after
+ // the declarator.
+ while (auto Specifier = isCXX11VirtSpecifier()) {
+ Diag(Tok, diag::err_virt_specifier_outside_class)
+ << VirtSpecifiers::getSpecifierName(Specifier)
+ << FixItHint::CreateRemoval(Tok.getLocation());
+ ConsumeToken();
+ }
// Look at the next token to make sure that this isn't a function
// declaration. We have to check this because __attribute__ might be the
// start of a function definition in GCC-extended K&R C.