diff mbox

[C] Fix PR44257

Message ID CAAgBjMkCciA23CXhWTYRGjR+VKP2-9b00KwKN8Fnszr0gGpbEA@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni June 19, 2015, 2:47 p.m. UTC
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.kulkarni@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 mbox

Patch

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;