[cfe-dev] Bugs 2746 and 3261

Anders Carlsson andersca at mac.com
Tue Jan 13 08:40:49 PST 2009


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)

Anders




More information about the cfe-dev mailing list