diff options
author | Nicolas Lesser <blitzrakete@gmail.com> | 2019-05-04 00:09:00 +0000 |
---|---|---|
committer | Nicolas Lesser <blitzrakete@gmail.com> | 2019-05-04 00:09:00 +0000 |
commit | 5fe2ddbdf47dddc90233e3240a3aa6bcdea8721f (patch) | |
tree | cfbf555d713619334ea8bf588e6a172095dcda7f /clang/lib/Sema/SemaDeclCXX.cpp | |
parent | a6b41d7c52ad4b8d2fd7f2f069645401b9bbc1e9 (diff) | |
download | bcm5719-llvm-5fe2ddbdf47dddc90233e3240a3aa6bcdea8721f.tar.gz bcm5719-llvm-5fe2ddbdf47dddc90233e3240a3aa6bcdea8721f.zip |
[clang] adding explicit(bool) from c++2a
this patch adds support for the explicit bool specifier.
Changes:
- The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
- The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
- Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
- Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
- The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
- Test for Semantic and Serialization were added.
This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.
Patch by Tyker
Differential Revision: https://reviews.llvm.org/D60934
llvm-svn: 359949
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index b90ab0457b2..b8740960fc5 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -657,14 +657,13 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Invalid = true; } - // FIXME: It's not clear what should happen if multiple declarations of a - // deduction guide have different explicitness. For now at least we simply - // reject any case where the explicitness changes. - auto *NewGuide = dyn_cast<CXXDeductionGuideDecl>(New); - if (NewGuide && NewGuide->isExplicitSpecified() != - cast<CXXDeductionGuideDecl>(Old)->isExplicitSpecified()) { - Diag(New->getLocation(), diag::err_deduction_guide_explicit_mismatch) - << NewGuide->isExplicitSpecified(); + // C++17 [temp.deduct.guide]p3: + // Two deduction guide declarations in the same translation unit + // for the same class template shall not have equivalent + // parameter-declaration-clauses. + if (isa<CXXDeductionGuideDecl>(New) && + !New->isFunctionTemplateSpecialization()) { + Diag(New->getLocation(), diag::err_deduction_guide_redeclared); Diag(Old->getLocation(), diag::note_previous_declaration); } @@ -8638,12 +8637,12 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R, R = Context.getFunctionType(ConvType, None, Proto->getExtProtoInfo()); // C++0x explicit conversion operators. - if (DS.isExplicitSpecified()) + if (DS.hasExplicitSpecifier() && !getLangOpts().CPlusPlus2a) Diag(DS.getExplicitSpecLoc(), getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_explicit_conversion_functions : diag::ext_explicit_conversion_functions) - << SourceRange(DS.getExplicitSpecLoc()); + << SourceRange(DS.getExplicitSpecRange()); } /// ActOnConversionDeclarator - Called by ActOnDeclarator to complete @@ -10866,6 +10865,28 @@ struct ComputingExceptionSpec { }; } +bool Sema::tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec) { + llvm::APSInt Result; + ExprResult Converted = CheckConvertedConstantExpression( + ExplicitSpec.getExpr(), Context.BoolTy, Result, CCEK_ExplicitBool); + ExplicitSpec.setExpr(Converted.get()); + if (Converted.isUsable() && !Converted.get()->isValueDependent()) { + ExplicitSpec.setKind(Result.getBoolValue() + ? ExplicitSpecKind::ResolvedTrue + : ExplicitSpecKind::ResolvedFalse); + return true; + } + ExplicitSpec.setKind(ExplicitSpecKind::Unresolved); + return false; +} + +ExplicitSpecifier Sema::ActOnExplicitBoolSpecifier(Expr *ExplicitExpr) { + ExplicitSpecifier ES(ExplicitExpr, ExplicitSpecKind::Unresolved); + if (!ExplicitExpr->isTypeDependent()) + tryResolveExplicitSpecifier(ES); + return ES; +} + static Sema::ImplicitExceptionSpecification ComputeDefaultedSpecialMemberExceptionSpec( Sema &S, SourceLocation Loc, CXXMethodDecl *MD, Sema::CXXSpecialMember CSM, @@ -11014,9 +11035,9 @@ CXXConstructorDecl *Sema::DeclareImplicitDefaultConstructor( = Context.DeclarationNames.getCXXConstructorName(ClassType); DeclarationNameInfo NameInfo(Name, ClassLoc); CXXConstructorDecl *DefaultCon = CXXConstructorDecl::Create( - Context, ClassDecl, ClassLoc, NameInfo, /*Type*/QualType(), - /*TInfo=*/nullptr, /*isExplicit=*/false, /*isInline=*/true, - /*isImplicitlyDeclared=*/true, Constexpr); + Context, ClassDecl, ClassLoc, NameInfo, /*Type*/ QualType(), + /*TInfo=*/nullptr, ExplicitSpecifier(), + /*isInline=*/true, /*isImplicitlyDeclared=*/true, Constexpr); DefaultCon->setAccess(AS_public); DefaultCon->setDefaulted(); @@ -11135,7 +11156,7 @@ Sema::findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *DerivedCtor = CXXConstructorDecl::Create( Context, Derived, UsingLoc, NameInfo, TInfo->getType(), TInfo, - BaseCtor->isExplicit(), /*Inline=*/true, + BaseCtor->getExplicitSpecifier(), /*Inline=*/true, /*ImplicitlyDeclared=*/true, Constexpr, InheritedConstructor(Shadow, BaseCtor)); if (Shadow->isInvalidDecl()) @@ -12588,8 +12609,9 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor( // member of its class. CXXConstructorDecl *CopyConstructor = CXXConstructorDecl::Create( Context, ClassDecl, ClassLoc, NameInfo, QualType(), /*TInfo=*/nullptr, - /*isExplicit=*/false, /*isInline=*/true, /*isImplicitlyDeclared=*/true, - Constexpr); + ExplicitSpecifier(), + /*isInline=*/true, + /*isImplicitlyDeclared=*/true, Constexpr); CopyConstructor->setAccess(AS_public); CopyConstructor->setDefaulted(); @@ -12718,8 +12740,9 @@ CXXConstructorDecl *Sema::DeclareImplicitMoveConstructor( // member of its class. CXXConstructorDecl *MoveConstructor = CXXConstructorDecl::Create( Context, ClassDecl, ClassLoc, NameInfo, QualType(), /*TInfo=*/nullptr, - /*isExplicit=*/false, /*isInline=*/true, /*isImplicitlyDeclared=*/true, - Constexpr); + ExplicitSpecifier(), + /*isInline=*/true, + /*isImplicitlyDeclared=*/true, Constexpr); MoveConstructor->setAccess(AS_public); MoveConstructor->setDefaulted(); |