diff mbox

[c++] : Fix for PR/65390

Message ID CAEwic4YNNdBKQ=ENqzbH7THHwdc5Z06QM3zUGe++wmqfkxjZXw@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz March 20, 2015, 2:53 p.m. UTC
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

+// { dg-error "variably modified type|trying to instantiate" "type" {
target *-*-* } 10 }

Comments

Jason Merrill March 24, 2015, 5:14 a.m. UTC | #1
On 03/20/2015 10:53 AM, Kai Tietz wrote:
>      * tree.c (strip_typedefs): Ignore alignment
>      difference during processing template.
>
> +      || (processing_template_decl
> +      && TYPE_ALIGN (t) != TYPE_ALIGN (result)))

Your change is actually ignoring alignment differences when *not* 
processing a template, which isn't what we want.

The problem is that the type is considered dependent in a template but 
is not actually dependent, so we can see the exact same type outside a 
template and it's not dependent.  So, this code is creating the difference:

>   /* We can only call value_dependent_expression_p on integral constant
>      expressions; treat non-constant expressions as dependent, too.  */
>   if (processing_template_decl
>       && (type_dependent_expression_p (size)
>           || !TREE_CONSTANT (size) || value_dependent_expression_p (size)))

Now that we have instantiation_dependent_expression_p, we should be able 
to use that instead of checking type/value dependency separately.

Jason
diff mbox

Patch

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" }
+}