aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-02-13 17:07:30 -0500
committerJason Merrill <jason@gcc.gnu.org>2015-02-13 17:07:30 -0500
commitef796bef889d8a1590430a9da06c40ec4977d79e (patch)
treea3d3d0ff70776f75d1e90655b7d95c53b16ab059 /gcc
parent8f895cf1ac7babe0c89533e8e9e6b6ca6bb33950 (diff)
downloadgcc-ef796bef889d8a1590430a9da06c40ec4977d79e.zip
gcc-ef796bef889d8a1590430a9da06c40ec4977d79e.tar.gz
gcc-ef796bef889d8a1590430a9da06c40ec4977d79e.tar.bz2
re PR c++/65054 (internal compiler error: in maybe_constant_value, at cp/constexpr.c:3646)
PR c++/65054 * pt.c (template_args_equal): Look through conversions here. * tree.c (cp_tree_equal): Not here. From-SVN: r220697
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c1
-rw-r--r--gcc/cp/pt.c17
-rw-r--r--gcc/cp/tree.c19
-rw-r--r--gcc/testsuite/g++.dg/expr/ptr-arith1.C7
5 files changed, 34 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e6d306e..0738e8b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-13 Jason Merrill <jason@redhat.com>
+
+ PR c++/65054
+ * pt.c (template_args_equal): Look through conversions here.
+ * tree.c (cp_tree_equal): Not here.
+
2015-02-13 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/60211
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 2b56cb2..d415dd4 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3638,7 +3638,6 @@ maybe_constant_value (tree t, tree decl)
r = cxx_eval_outermost_constant_expr (t, true, true, decl);
#ifdef ENABLE_CHECKING
- /* cp_tree_equal looks through NOPs, so allow them. */
gcc_assert (r == t
|| CONVERT_EXPR_P (t)
|| TREE_CODE (t) == VIEW_CONVERT_EXPR
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3317dad..9a00d0d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7324,7 +7324,22 @@ template_args_equal (tree ot, tree nt)
else if (TREE_CODE (ot) == TREE_VEC || TYPE_P (ot))
return 0;
else
- return cp_tree_equal (ot, nt);
+ {
+ /* Try to treat a template non-type argument that has been converted
+ to the parameter type as equivalent to one that hasn't yet. */
+ for (enum tree_code code1 = TREE_CODE (ot);
+ CONVERT_EXPR_CODE_P (code1)
+ || code1 == NON_LVALUE_EXPR;
+ code1 = TREE_CODE (ot))
+ ot = TREE_OPERAND (ot, 0);
+ for (enum tree_code code2 = TREE_CODE (nt);
+ CONVERT_EXPR_CODE_P (code2)
+ || code2 == NON_LVALUE_EXPR;
+ code2 = TREE_CODE (nt))
+ nt = TREE_OPERAND (nt, 0);
+
+ return cp_tree_equal (ot, nt);
+ }
}
/* Returns 1 iff the OLDARGS and NEWARGS are in fact identical sets of
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index c51e42d..c8e6f0c 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2745,20 +2745,8 @@ cp_tree_equal (tree t1, tree t2)
if (!t1 || !t2)
return false;
- for (code1 = TREE_CODE (t1);
- CONVERT_EXPR_CODE_P (code1)
- || code1 == NON_LVALUE_EXPR;
- code1 = TREE_CODE (t1))
- t1 = TREE_OPERAND (t1, 0);
- for (code2 = TREE_CODE (t2);
- CONVERT_EXPR_CODE_P (code2)
- || code2 == NON_LVALUE_EXPR;
- code2 = TREE_CODE (t2))
- t2 = TREE_OPERAND (t2, 0);
-
- /* They might have become equal now. */
- if (t1 == t2)
- return true;
+ code1 = TREE_CODE (t1);
+ code2 = TREE_CODE (t2);
if (code1 != code2)
return false;
@@ -2996,6 +2984,9 @@ cp_tree_equal (tree t1, tree t2)
case DYNAMIC_CAST_EXPR:
case IMPLICIT_CONV_EXPR:
case NEW_EXPR:
+ CASE_CONVERT:
+ case NON_LVALUE_EXPR:
+ case VIEW_CONVERT_EXPR:
if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
return false;
/* Now compare operands as usual. */
diff --git a/gcc/testsuite/g++.dg/expr/ptr-arith1.C b/gcc/testsuite/g++.dg/expr/ptr-arith1.C
new file mode 100644
index 0000000..71e97f7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/expr/ptr-arith1.C
@@ -0,0 +1,7 @@
+// PR c++/65054
+
+const char *
+foo (void)
+{
+ return ((char *const) "abc" + 1);
+}