Hi,
C FE rejects incomplete type for expression in typeof.

struct foo;
struct foo *p;
typeof (struct foo) *q;  // accepted
typeof (*p) *q;  // error: dereferencing pointer to incomplete type.

The attached patch tries to fix it.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
OK for trunk if testing passes ?

Thank you,
Prathamesh
2015-06-19  Prathamesh Kulkarni  <prathamesh.kulka...@linaro.org>

        PR c/44257
        * c-typeck.c (build_indirect_ref): Add check !in_typeof before 
reporting incomplete type error.
        * gcc.dg/pr44257: New test-case.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 636e0bb..5dbbea7 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2389,7 +2389,7 @@ build_indirect_ref (location_t loc, tree ptr, 
ref_operator errstring)
 
          ref = build1 (INDIRECT_REF, t, pointer);
 
-         if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
+         if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE && 
!in_typeof)
            {
              if (!C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr)))
                {
diff --git a/gcc/testsuite/gcc.dg/pr44257.c b/gcc/testsuite/gcc.dg/pr44257.c
new file mode 100644
index 0000000..9657d2a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr44257.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+struct foo;
+struct foo *p;
+__typeof (*p) *q;

Reply via email to