On Mon, Nov 26, 2012 at 7:36 PM, Rafael Ávila de Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">GCC accepts<br>
<br>
typedef int IA[];<br>
typedef int A10[10];<br>
static A10 *f(void);<br>
static IA  *f(void);<br>
void g(void) {<br>
  (void)sizeof(*f());<br>
}<br>
<br>
but clang used to reject it with:<br>
<br>
    invalid application of 'sizeof' to an incomplete type 'IA' (aka 'int []')<br>
<br>
The intention of c99's 6.2.7 seems to be that we should use the composite type<br>
and accept as gcc does.<br>
---<br>
 lib/Sema/SemaDecl.cpp   |  7 +++++++<br>
 test/Sema/merge-decls.c | 11 +++++++++++<br>
 2 files changed, 18 insertions(+)<br>
<br>
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp<br>
index 6a9065e..72b7f26 100644<br>
--- a/lib/Sema/SemaDecl.cpp<br>
+++ b/lib/Sema/SemaDecl.cpp<br>
@@ -2402,6 +2402,13 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,<br>
   if (getLangOpts().CPlusPlus)<br>
     return MergeCXXFunctionDecl(New, Old, S);<br>
<br>
+  // Merge the types so the we get the composites for the return and argument<br>
+  // types. Do that only if both decls are not K&R.<br></div></div></blockquote><div><br></div><div>Why do you not merge functions with no prototype?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">
+  if (Old->hasPrototype() && New->hasPrototype()) {<br>
+    QualType Merged = Context.mergeTypes(Old->getType(), New->getType());<br>
+    New->setType(Merged);<br>
+  }<br>
+<br>
   return false;<br>
 }<br>
<br>
diff --git a/test/Sema/merge-decls.c b/test/Sema/merge-decls.c<br>
index da3e245..9789587 100644<br>
--- a/test/Sema/merge-decls.c<br>
+++ b/test/Sema/merge-decls.c<br>
@@ -48,3 +48,14 @@ void test1_g(void)<br>
   }<br>
   (void)sizeof(*test1_f());<br>
 }<br>
+<br>
+typedef int test2_IA[];<br>
+typedef int test2_A10[10];<br>
+<br>
+static test2_A10 *test2_f(void);<br>
+static test2_IA  *test2_f(void);<br>
+<br>
+void test2_g(void)<br>
+{<br>
+  (void)sizeof(*test2_f());<br>
+}<br>
--<br>
1.7.11.7<br>
<br>
</div></div></blockquote></div><br>