]> granicus.if.org Git - clang/commitdiff
Use the unqualified type for GCCs struct/union cast extension
authorAnders Carlsson <andersca@mac.com>
Tue, 13 Jan 2009 17:00:51 +0000 (17:00 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 13 Jan 2009 17:00:51 +0000 (17:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62170 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/struct-cast.c [new file with mode: 0644]

index 2721bb8dc60f8d23148b2b08a93703223f0e49d4..41881a2e5bb35ec518b68e6b32f7f239e17c8903 100644 (file)
@@ -1912,8 +1912,8 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr) {
     // 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)
diff --git a/test/Sema/struct-cast.c b/test/Sema/struct-cast.c
new file mode 100644 (file)
index 0000000..734be80
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: clang -fsyntax-only %s -verify
+
+struct S {
+ int one;
+ int two;
+};
+
+struct S const foo(void);
+
+struct S tmp;
+
+void priv_sock_init() {
+  tmp = (struct S)foo();
+}