aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorAlejandro Álvarez Ayllón <alejandro.alvarez@sonarsource.com>2025-10-02 07:11:31 -0700
committerGitHub <noreply@github.com>2025-10-02 16:11:31 +0200
commitb147019f8b11cd491f331bd707f764786792665e (patch)
treec71491d0dcca176d30e3247f072da4f9858d9a3e /clang/lib/Parse/ParseDecl.cpp
parent706b79002e21b571888db7f275bf5ed00e7cce41 (diff)
downloadllvm-b147019f8b11cd491f331bd707f764786792665e.zip
llvm-b147019f8b11cd491f331bd707f764786792665e.tar.gz
llvm-b147019f8b11cd491f331bd707f764786792665e.tar.bz2
[clang] Preserve `externs` following broken declarations (#161641)
Treat them as namespaces: if they are at the beginning of the line, they are likely a good recovery point. For instance, in ```cpp 1.3.0 extern "C" { extern int foo(); extern "C++" { namespace bar { void baz(); }; } } namespace {} ``` Everything until `namespace`... is gone from the AST. Headers (like libc's C++ `math.h`) can be included from an `extern "C"` context, and they do an `extern "C++"` back again before including C++ headers (like `__type_traits`). However, a malformed declaration just before the include (as the orphan `1.3.0` in the example) causes everything from these standard headers to go missing. This patch updates the heuristic to try to recover from the first `extern` keyword seen, pretty much as it is done for `namespace`. CPP-4478
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 22c01c4..d6cd7eb 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2083,6 +2083,9 @@ void Parser::SkipMalformedDecl() {
return;
break;
+ case tok::kw_extern:
+ // 'extern' at the start of a line is almost certainly a good
+ // place to pick back up parsing
case tok::kw_namespace:
// 'namespace' at the start of a line is almost certainly a good
// place to pick back up parsing, except in an Objective-C