[clang] [clang][ASTImporter] Fix of unchecked Error object (NFC) (PR #112688)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 03:19:35 PDT 2024
https://github.com/balazske created https://github.com/llvm/llvm-project/pull/112688
After a previous fix and commit 30a9cac error handling in function 'importTemplateParameterDefaultArgument' was not correct because std::move was removed from return of an Error object and this caused crash "Error value was Success" in some cases.
>From 0694ea396728fe34f031fa1102460f56da4d3822 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <balazs.keri at ericsson.com>
Date: Thu, 17 Oct 2024 12:03:55 +0200
Subject: [PATCH] [clang][ASTImporter] Fix of unchecked Error object (NFC)
After a previous fix and commit 30a9cac error handling
in function 'importTemplateParameterDefaultArgument' was not correct
because std::move was removed from return of an Error object
and this caused crash "Error value was Success" in some cases.
---
clang/lib/AST/ASTImporter.cpp | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 020a2f396b5aa0..e7a6509167f0a0 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -362,24 +362,24 @@ namespace clang {
template <typename TemplateParmDeclT>
Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
TemplateParmDeclT *ToD) {
- Error Err = Error::success();
if (D->hasDefaultArgument()) {
if (D->defaultArgumentWasInherited()) {
- auto *ToInheritedFrom = const_cast<TemplateParmDeclT *>(
- importChecked(Err, D->getDefaultArgStorage().getInheritedFrom()));
- if (Err)
- return Err;
+ Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
+ import(D->getDefaultArgStorage().getInheritedFrom());
+ if (!ToInheritedFromOrErr)
+ return ToInheritedFromOrErr.takeError();
+ TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
if (!ToInheritedFrom->hasDefaultArgument()) {
// Resolve possible circular dependency between default value of the
// template argument and the template declaration.
- const auto ToInheritedDefaultArg =
- importChecked(Err, D->getDefaultArgStorage()
- .getInheritedFrom()
- ->getDefaultArgument());
- if (Err)
- return Err;
+ Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
+ import(D->getDefaultArgStorage()
+ .getInheritedFrom()
+ ->getDefaultArgument());
+ if (!ToInheritedDefaultArgOrErr)
+ return ToInheritedDefaultArgOrErr.takeError();
ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
- ToInheritedDefaultArg);
+ *ToInheritedDefaultArgOrErr);
}
ToD->setInheritedDefaultArgument(ToD->getASTContext(),
ToInheritedFrom);
@@ -395,7 +395,7 @@ namespace clang {
*ToDefaultArgOrErr);
}
}
- return Err;
+ return Error::success();
}
public:
More information about the cfe-commits
mailing list