[cfe-dev] Bugs 2746 and 3261

Douglas Gregor dgregor at apple.com
Tue Jan 13 08:50:47 PST 2009


On Jan 13, 2009, at 8:40 AM, Anders Carlsson wrote:
> 13 jan 2009 kl. 08.30 skrev Roberto Bagnara:
>>
>> Hi Eli,
>>
>> why should we restrict to unions?  For instance, the following
>> testcase is a simplified one coming from vstfpd-0.9.2:
>>
>> struct S {
>>   int one;
>>   int two;
>> };
>>
>> struct S const foo(void) ;
>>
>> struct S tmp ;
>>
>> void priv_sock_init() {
>>  tmp = (struct S) foo();
>> }
>>
>> All the best,
>>
>>   Roberto
>
> Hi Roberto,
>
> I think the fix for the above test would be something like


> Index: lib/Sema/SemaExpr.cpp
> ===================================================================
> --- lib/Sema/SemaExpr.cpp	(revision 62169)
> +++ lib/Sema/SemaExpr.cpp	(working copy)
> @@ -1912,8 +1912,8 @@
>      // We can't check any more until template instantiation time.
>    } else if (!castType->isScalarType() && !castType->isVectorType 
> ()) {
>      // GCC struct/union extension: allow cast to self.
> -    if (Context.getCanonicalType(castType) !=
> -        Context.getCanonicalType(castExpr->getType()) ||
> +    if (Context.getCanonicalType(castType).getUnqualifiedType() !=
> +        Context.getCanonicalType(castExpr-
>> getType().getUnqualifiedType()) ||
>          (!castType->isStructureType() && !castType->isUnionType())) {
>        // Reject any other conversions to non-scalar types.
>        return Diag(TyR.getBegin(),
> diag::err_typecheck_cond_expect_scalar)


Yep, that'll do it. Please go ahead and commit.

	- Doug



More information about the cfe-dev mailing list