[cfe-commits] r83710 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaType.cpp test/SemaCXX/exception-spec.cpp

Douglas Gregor dgregor at apple.com
Mon Oct 12 09:48:54 PDT 2009


On Oct 10, 2009, at 5:04 AM, Sebastian Redl wrote:

> Author: cornedbee
> Date: Sat Oct 10 07:04:10 2009
> New Revision: 83710
>
> URL: http://llvm.org/viewvc/llvm-project?rev=83710&view=rev
> Log:
> Implement the core checking for compatible exception specifications  
> in assignment and initialization.

Cool.

> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Oct 10  
> 07:04:10 2009
> @@ -363,6 +363,8 @@
> def err_override_exception_spec : Error<
>   "exception specification of overriding function is more lax than "
>   "base version">;
> +def err_incompatible_exception_specs : Error<
> +  "target exception specification is not superset of source">;

It would be nice if we said a little more about what types the target  
is missing in its exception specification, but it's not critical.

> +bool Sema::CheckExceptionSpecCompatibility(Expr *From, QualType  
> ToType)
> +{
> +  // First we check for applicability.
> +  // Target type must be a function, function pointer or function  
> reference.
> +  if (const PointerType *PtrTy = ToType->getAs<PointerType>())
> +    ToType = PtrTy->getPointeeType();
> +  else if (const ReferenceType *RefTy = ToType->getAs<ReferenceType> 
> ())
> +    ToType = RefTy->getPointeeType();

Or a member function pointer?

> +  const FunctionProtoType *ToFunc = ToType->getAs<FunctionProtoType> 
> ();
> +  if (!ToFunc)
> +    return false;
> +
> +  // SourceType must be a function or function pointer.
> +  // References are treated as functions.
> +  QualType FromType = From->getType();
> +  if (const PointerType *PtrTy = FromType->getAs<PointerType>())
> +    FromType = PtrTy->getPointeeType();

Or a member function pointer?

Thanks, Sebastian!

	- Doug



More information about the cfe-commits mailing list