[clang] [clang][AST] fix ast-print of `extern <lang>` with >=2 declarators (PR #93131)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 17:38:29 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 2ba08386156ef25913b1bee170d8fe95aaceb234 ae5225aa51a0a8f79ed134d9d5013d5774d2c04d -- clang/test/AST/ast-print-language-linkage.cpp clang/lib/AST/DeclPrinter.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 60d5074e69..6a78bc01c1 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -650,8 +650,10 @@ static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
/// - nullptr in any other case
static const char *tryGetUnbracedLinkageLanguage(const Decl *D) {
const auto *SD = dyn_cast<LinkageSpecDecl>(D->getDeclContext());
- if (!SD) return nullptr;
- if (SD->hasBraces()) return nullptr;
+ if (!SD)
+ return nullptr;
+ if (SD->hasBraces())
+ return nullptr;
if (SD->getLanguage() == LinkageSpecLanguageIDs::C)
return "C";
assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX &&
@@ -679,7 +681,8 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D);
if (!Policy.SuppressSpecifiers) {
if (const char *lang = tryGetUnbracedLinkageLanguage(D)) {
- assert(D->getStorageClass() == SC_None); // the "extern" specifier is implicit
+ assert(D->getStorageClass() ==
+ SC_None); // the "extern" specifier is implicit
Out << "extern \"" << lang << "\" ";
}
switch (D->getStorageClass()) {
@@ -953,7 +956,8 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
if (!Policy.SuppressSpecifiers) {
if (const char *lang = tryGetUnbracedLinkageLanguage(D)) {
- assert(D->getStorageClass() == SC_None); // the "extern" specifier is implicit
+ assert(D->getStorageClass() ==
+ SC_None); // the "extern" specifier is implicit
Out << "extern \"" << lang << "\" ";
}
StorageClass SC = D->getStorageClass();
@@ -1089,7 +1093,7 @@ void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
prettyPrintAttributes(D);
if (const char *lang = tryGetUnbracedLinkageLanguage(D))
- Out << "extern \"" << lang << "\";";
+ Out << "extern \"" << lang << "\";";
}
void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/93131
More information about the cfe-commits
mailing list