From d09a51c299ab277119b2e96b26ed9864c6404ebe Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 3 Mar 2015 01:50:05 +0000 Subject: Sema: Properly initialize the thrown exception object We would create the exception object with the wrong qualifiers, ensuring that the wrong copy constructor would get called. llvm-svn: 231049 --- clang/lib/AST/ASTContext.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'clang/lib/AST/ASTContext.cpp') diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 8a99162c1cf..fc40f7e8e23 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -4338,6 +4338,19 @@ QualType ASTContext::getSignatureParameterType(QualType T) const { return T.getUnqualifiedType(); } +QualType ASTContext::getExceptionObjectType(QualType T) const { + // C++ [except.throw]p3: + // A throw-expression initializes a temporary object, called the exception + // object, the type of which is determined by removing any top-level + // cv-qualifiers from the static type of the operand of throw and adjusting + // the type from "array of T" or "function returning T" to "pointer to T" + // or "pointer to function returning T", [...] + T = getVariableArrayDecayedType(T); + if (T->isArrayType() || T->isFunctionType()) + T = getDecayedType(T); + return T.getUnqualifiedType(); +} + /// getArrayDecayedType - Return the properly qualified result of decaying the /// specified array type to a pointer. This operation is non-trivial when /// handling typedefs etc. The canonical type of "T" must be an array type, -- cgit v1.2.3