[cfe-commits] r122226 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp test/Parser/MicrosoftExtensions.c test/Parser/MicrosoftExtensions.cpp
Douglas Gregor
dgregor at apple.com
Mon Dec 20 07:23:38 PST 2010
On Dec 19, 2010, at 7:51 PM, Francois Pichet wrote:
> Author: fpichet
> Date: Sun Dec 19 21:51:03 2010
> New Revision: 122226
>
> URL: http://llvm.org/viewvc/llvm-project?rev=122226&view=rev
> Log:
> Emit an error if operator __uuidof() is called on a type with no associated GUID.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/Parser/MicrosoftExtensions.c
> cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=122226&r1=122225&r2=122226&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Dec 19 21:51:03 2010
> @@ -2595,6 +2595,8 @@
> "you need to include <typeinfo> before using the 'typeid' operator">;
> def err_need_header_before_ms_uuidof : Error<
> "you need to include <guiddef.h> before using the '__uuidof' operator">;
> +def err_uuidof_without_guid : Error<
> + "cannot call operator __uuidof on a type with no GUID">;
> def err_incomplete_typeid : Error<"'typeid' of incomplete type %0">;
> def err_static_illegal_in_new : Error<
> "the 'static' modifier for the array size is not legal in new expressions">;
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=122226&r1=122225&r2=122226&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Dec 19 21:51:03 2010
> @@ -372,11 +372,29 @@
> return BuildCXXTypeId(TypeInfoType, OpLoc, (Expr*)TyOrExpr, RParenLoc);
> }
>
> +// Get the CXXRecordDecl associated with QT bypassing 1 level of pointer,
> +// reference or array type.
> +static CXXRecordDecl *GetCXXRecordOfUuidArg(QualType QT)
> +{
> + Type* Ty = QT.getTypePtr();;
> + if (QT->isPointerType() || QT->isReferenceType())
> + Ty = QT->getPointeeType().getTypePtr();
> + else if (QT->isArrayType())
> + Ty = cast<ArrayType>(QT)->getElementType().getTypePtr();
> +
> + return Ty->getAsCXXRecordDecl();
> +}
> +
> /// \brief Build a Microsoft __uuidof expression with a type operand.
> ExprResult Sema::BuildCXXUuidof(QualType TypeInfoType,
> SourceLocation TypeidLoc,
> TypeSourceInfo *Operand,
> SourceLocation RParenLoc) {
> + // Make sure Operand has an associated GUID.
> + CXXRecordDecl* RD = GetCXXRecordOfUuidArg(Operand->getType());
> + if (!RD || !RD->getAttr<UuidAttr>())
> + return ExprError(Diag(TypeidLoc, diag::err_uuidof_without_guid));
> +
I assume you'll be adding a "Operand->getType()->isDependent()" check at some point, to handle the use of __uuidof in templates?
- Doug
More information about the cfe-commits
mailing list