From bc12e920681c7bdf6def76c8f833253c4f49183a Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 13 Jan 2009 17:00:51 +0000 Subject: [PATCH] Use the unqualified type for GCCs struct/union cast extension llvm-svn: 62170 --- clang/lib/Sema/SemaExpr.cpp | 4 ++-- clang/test/Sema/struct-cast.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 clang/test/Sema/struct-cast.c diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 2721bb8dc60f..41881a2e5bb3 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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/clang/test/Sema/struct-cast.c b/clang/test/Sema/struct-cast.c new file mode 100644 index 000000000000..734be804e6e5 --- /dev/null +++ b/clang/test/Sema/struct-cast.c @@ -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(); +} -- GitLab