Parsing, ASTs, and semantic analysis for the declaration of conversion
functions in C++, e.g.,
struct X {
operator bool() const;
};
Note that these conversions don't actually do anything, since we don't
yet have the ability to use them for implicit or explicit conversions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58860 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index fd94c80..12a4b08 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -38,6 +38,11 @@
return 0;
}
+std::string Sema::getTypeAsString(TypeTy *Type) {
+ QualType Ty = QualType::getFromOpaquePtr(Type);
+ return Ty.getAsString();
+}
+
DeclContext *Sema::getDCParent(DeclContext *DC) {
// If CurContext is a ObjC method, getParent() will return NULL.
if (isa<ObjCMethodDecl>(DC))
@@ -835,6 +840,22 @@
if (isInvalidDecl)
NewFD->setInvalidDecl();
+ } else if (D.getKind() == Declarator::DK_Conversion) {
+ if (D.getContext() != Declarator::MemberContext) {
+ Diag(D.getIdentifierLoc(),
+ diag::err_conv_function_not_member);
+ return 0;
+ } else {
+ bool isInvalidDecl = CheckConversionDeclarator(D, R, SC);
+
+ NewFD = CXXConversionDecl::Create(Context,
+ cast<CXXRecordDecl>(CurContext),
+ D.getIdentifierLoc(), II, R,
+ isInline, isExplicit);
+
+ if (isInvalidDecl)
+ NewFD->setInvalidDecl();
+ }
} else if (D.getContext() == Declarator::MemberContext) {
// This is a C++ method declaration.
NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(CurContext),
@@ -931,6 +952,8 @@
return ActOnConstructorDeclarator(Constructor);
else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(NewFD))
return ActOnDestructorDeclarator(Destructor);
+ else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(NewFD))
+ return ActOnConversionDeclarator(Conversion);
// Extra checking for C++ overloaded operators (C++ [over.oper]).
if (NewFD->isOverloadedOperator() &&