aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2020-11-30 15:43:48 -0800
committerReid Kleckner <rnk@google.com>2020-11-30 16:29:29 -0800
commit43b5b485a203f190ee4d5d3cab19c44ca865d316 (patch)
tree8b3e92b85cb6e27ef7d5deb02836892f6e1ddc60 /clang
parent[InlineCost] prefer range-for. NFC (diff)
downloadllvm-project-43b5b485a203f190ee4d5d3cab19c44ca865d316.tar.gz
llvm-project-43b5b485a203f190ee4d5d3cab19c44ca865d316.tar.bz2
llvm-project-43b5b485a203f190ee4d5d3cab19c44ca865d316.zip
Fix GCC 5.3 compile error in ASTImporter code
Try to simplify this code a different way: use less Expected, more outparams.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/ASTImporter.cpp62
1 files changed, 27 insertions, 35 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1b014314996b..7a1415b658b8 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -202,6 +202,9 @@ namespace clang {
return *MaybeVal;
}
+ ExplicitSpecifier importExplicitSpecifier(Error &Err,
+ ExplicitSpecifier ESpec);
+
// Wrapper for an overload set.
template <typename ToDeclT> struct CallOverloadedCreateFun {
template <typename... Args> decltype(auto) operator()(Args &&... args) {
@@ -3153,6 +3156,14 @@ bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) {
return false;
}
+ExplicitSpecifier
+ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
+ Expr *ExplicitExpr = ESpec.getExpr();
+ if (ExplicitExpr)
+ ExplicitExpr = importChecked(Err, ESpec.getExpr());
+ return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
+}
+
ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D);
@@ -3329,34 +3340,17 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
return ToPOrErr.takeError();
}
- // Common code to import an explicit specifier of different kind of functions.
- auto ImportExplicitExpr = [this, &Err](auto *Fun) -> ExpectedExpr {
- Expr *ExplicitExpr = nullptr;
- if (Fun->getExplicitSpecifier().getExpr()) {
- ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr());
- if (Err)
- return std::move(Err);
- }
- return ExplicitExpr;
- };
-
// Create the imported function.
FunctionDecl *ToFunction = nullptr;
if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
- Expr *ExplicitExpr = nullptr;
- if (FromConstructor->getExplicitSpecifier().getExpr()) {
- auto Imp = import(FromConstructor->getExplicitSpecifier().getExpr());
- if (!Imp)
- return Imp.takeError();
- ExplicitExpr = *Imp;
- }
+ ExplicitSpecifier ESpec =
+ importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
+ if (Err)
+ return std::move(Err);
if (GetImportedOrCreateDecl<CXXConstructorDecl>(
ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
- ToInnerLocStart, NameInfo, T, TInfo,
- ExplicitSpecifier(
- ExplicitExpr,
- FromConstructor->getExplicitSpecifier().getKind()),
- D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
+ ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->isInlineSpecified(),
+ D->isImplicit(), D->getConstexprKind(),
InheritedConstructor(), // FIXME: Properly import inherited
// constructor info
TrailingRequiresClause))
@@ -3381,14 +3375,13 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
} else if (CXXConversionDecl *FromConversion =
dyn_cast<CXXConversionDecl>(D)) {
- ExpectedExpr ExplicitExpr = ImportExplicitExpr(FromConversion);
- if (!ExplicitExpr)
- return ExplicitExpr.takeError();
+ ExplicitSpecifier ESpec =
+ importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
+ if (Err)
+ return std::move(Err);
if (GetImportedOrCreateDecl<CXXConversionDecl>(
ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
- ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(),
- ExplicitSpecifier(*ExplicitExpr,
- FromConversion->getExplicitSpecifier().getKind()),
+ ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), ESpec,
D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
return ToFunction;
} else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
@@ -3399,13 +3392,12 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
SourceLocation(), TrailingRequiresClause))
return ToFunction;
} else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
- ExpectedExpr ExplicitExpr = ImportExplicitExpr(Guide);
- if (!ExplicitExpr)
- return ExplicitExpr.takeError();
+ ExplicitSpecifier ESpec =
+ importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
+ if (Err)
+ return std::move(Err);
if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
- ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
- ExplicitSpecifier(*ExplicitExpr,
- Guide->getExplicitSpecifier().getKind()),
+ ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
NameInfo, T, TInfo, ToEndLoc))
return ToFunction;
cast<CXXDeductionGuideDecl>(ToFunction)