This is the mail archive of the gcc-patches@gcc.gnu.org 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]

C++ PATCH for c++/63415 (value-dependent int(T{}))


T{} is expressed as a CONSTRUCTOR with TREE_HAS_CONSTRUCTOR set, so we need to consider the type and not just assume that all CONSTRUCTORs have init-list type.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 81e370f51099c049313b9f6f1d8910e2475fbbcf
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Oct 8 17:15:07 2014 -0400

    	PR c++/63415
    	* pt.c (value_dependent_expression_p) [CONSTRUCTOR]: Check the type.
    	(iterative_hash_template_arg): Likewise.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 7d380e5..85af59d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1598,6 +1598,7 @@ iterative_hash_template_arg (tree arg, hashval_t val)
     case CONSTRUCTOR:
       {
 	tree field, value;
+	iterative_hash_template_arg (TREE_TYPE (arg), val);
 	FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (arg), i, field, value)
 	  {
 	    val = iterative_hash_template_arg (field, val);
@@ -21062,6 +21063,8 @@ value_dependent_expression_p (tree expression)
       {
 	unsigned ix;
 	tree val;
+	if (dependent_type_p (TREE_TYPE (expression)))
+	  return true;
 	FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expression), ix, val)
 	  if (value_dependent_expression_p (val))
 	    return true;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist8.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist8.C
new file mode 100644
index 0000000..3d859a8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist8.C
@@ -0,0 +1,7 @@
+// PR c++/63415
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct A {
+  static constexpr int value = int(T{});
+};

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