[patch c++]: Fix for PR/65390

Kai Tietz ktietz70@googlemail.com
Fri Mar 20 14:53:00 GMT 2015


Hello,

the problem here is that for cases of vla-array-types, the types don't
get finally layouted in build_cplus_array_type.  So the type-alignment
isn't set in such cases for the resulting type.

ChangeLog

2015-03-20  Kai Tietz  <ktietz@redhat.com>

    PR c++/65390
    * tree.c (strip_typedefs): Ignore alignment
    difference during processing template.

2015-03-20  Kai Tietz  <ktietz@redhat.com>

    PR c++/65390
    * g++.dg/template/pr65390.C: New file.

Tested on x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: gcc/gcc/cp/tree.c
===================================================================
--- gcc.orig/gcc/cp/tree.c
+++ gcc/gcc/cp/tree.c
@@ -1356,7 +1356,8 @@ strip_typedefs (tree t)
   if (!result)
       result = TYPE_MAIN_VARIANT (t);
   if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
-      || TYPE_ALIGN (t) != TYPE_ALIGN (result))
+      || (processing_template_decl
+      && TYPE_ALIGN (t) != TYPE_ALIGN (result)))
     {
       gcc_assert (TYPE_USER_ALIGN (t));
       if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
Index: gcc/gcc/testsuite/g++.dg/template/pr65390.C
===================================================================
--- /dev/null
+++ gcc/gcc/testsuite/g++.dg/template/pr65390.C
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "-Wno-vla" }
+template<typename T> struct shared_ptr { };
+
+template<typename T, typename Arg>
+shared_ptr<T> make_shared(Arg) { return shared_ptr<T>(); } // {
dg-message "note" }
+// { dg-warning "ignoring attributes" "template" { target *-*-* } 6 }
+
+void f(int n){
+  make_shared<int[n]>(1); // { dg-error "no matching" }
+}
+// { dg-error "variably modified type|trying to instantiate" "type" {
target *-*-* } 10 }



More information about the Gcc-patches mailing list