[clang] [clang][ASTImporter] Fix of unchecked Error object (NFC) (PR #112688)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 03:20:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Balázs Kéri (balazske)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/112688.diff
1 Files Affected:
- (modified) clang/lib/AST/ASTImporter.cpp (+13-13)
``````````diff
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:
``````````
</details>
https://github.com/llvm/llvm-project/pull/112688
More information about the cfe-commits
mailing list