[gcc r9-9043] c++: Distinguish alignof and __alignof__ in cp_tree_equal [PR97273]
Patrick Palka
ppalka@gcc.gnu.org
Fri Nov 13 14:23:23 GMT 2020
https://gcc.gnu.org/g:9df05884b3a30d32744a070d3fc5780b7323231a
commit r9-9043-g9df05884b3a30d32744a070d3fc5780b7323231a
Author: Patrick Palka <ppalka@redhat.com>
Date: Wed Oct 7 10:49:00 2020 -0400
c++: Distinguish alignof and __alignof__ in cp_tree_equal [PR97273]
cp_tree_equal currently considers alignof the same as __alignof__, but
these operators are semantically different ever since r8-7957. In the
testcase below, this causes the second static_assert to fail on targets
where alignof(double) != __alignof__(double) because the specialization
table (which uses cp_tree_equal as its equality predicate) conflates the
two dependent specializations integral_constant<__alignof__(T)> and
integral_constant<alignof(T)>.
This patch makes cp_tree_equal distinguish between these two operators
by inspecting the ALIGNOF_EXPR_STD_P flag.
gcc/cp/ChangeLog:
PR c++/88115
PR libstdc++/97273
* tree.c (cp_tree_equal) <case ALIGNOF_EXPR>: Return false if
ALIGNOF_EXPR_STD_P differ.
gcc/testsuite/ChangeLog:
PR c++/88115
PR libstdc++/97273
* g++.dg/template/alignof3.C: New test.
(cherry picked from commit 592fe221735bdaa375b1834dd49ce125d0b600d8)
Diff:
---
gcc/cp/tree.c | 3 +++
gcc/testsuite/g++.dg/template/alignof3.C | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 7c68706640c..fb32b33e39a 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3738,6 +3738,9 @@ cp_tree_equal (tree t1, tree t2)
if (SIZEOF_EXPR_TYPE_P (t2))
o2 = TREE_TYPE (o2);
}
+ else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
+ return false;
+
if (TREE_CODE (o1) != TREE_CODE (o2))
return false;
if (TYPE_P (o1))
diff --git a/gcc/testsuite/g++.dg/template/alignof3.C b/gcc/testsuite/g++.dg/template/alignof3.C
new file mode 100644
index 00000000000..e573727c5f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/alignof3.C
@@ -0,0 +1,13 @@
+// PR c++/88115
+// { dg-do compile { target c++11 } }
+
+template<int __v>
+struct integral_constant {
+ static constexpr int value = __v;
+};
+
+template <class T> using StdAlignOf = integral_constant<alignof(T)>;
+template <class T> using GCCAlignOf = integral_constant<__alignof__(T)>;
+
+static_assert(StdAlignOf<double>::value == alignof(double), "");
+static_assert(GCCAlignOf<double>::value == __alignof__(double), "");
More information about the Gcc-cvs
mailing list