This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: PATCH to c_sizeof_or_alignof_type for c++/42623

In this function, other errors result in returning error_mark_node, but for some reason an incomplete type wasn't doing so, which confused the template code into thinking that it was OK to take sizeof such a type.

Tested x86_64-pc-linux-gnu. OK for trunk?
commit cc83c8ac93ab253b2095403ed1dfd87f28f758f1
Author: Jason Merrill <>
Date:   Tue Jan 5 14:26:44 2010 -0500

    	PR c++/42623
    	* c-common.c (c_sizeof_or_alignof_type): Return error_mark_node
    	for incomplete type.

diff --git a/gcc/c-common.c b/gcc/c-common.c
index 32dc21e..5772b83 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -4390,7 +4390,7 @@ c_sizeof_or_alignof_type (location_t loc,
       if (complain)
 	error_at (loc, "invalid application of %qs to incomplete type %qT ",
 		  op_name, type);
-      value = size_zero_node;
+      return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/template/sizeof13.C b/gcc/testsuite/g++.dg/template/sizeof13.C
new file mode 100644
index 0000000..2f4a26e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/sizeof13.C
@@ -0,0 +1,17 @@
+// PR c++/42623
+// We should choose f(B) because f(A<undef>) involves applying sizeof to
+// an incomplete class, so it is removed by SFINAE.
+// { dg-do link }
+struct undef;
+template <typename U, int N = sizeof(U)> struct A { A(int); };
+template <typename U> void f(A<U>);
+template <typename U> struct B { B(int) { } };
+template <typename U> void f(B<U>) { }
+int main()
+  f<undef>(0);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]