aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-03-16 16:06:27 -0400
committerJason Merrill <jason@redhat.com>2021-03-16 17:47:22 -0400
commita4101e5aafc512dc32b8d529b2bafb116a3612de (patch)
treee5e250e144643a110b9efeddd3f279b8d2b13bf2
parent0251051db64f13c9a31a05c8133c31dc50b2b235 (diff)
downloadgcc-a4101e5aafc512dc32b8d529b2bafb116a3612de.zip
gcc-a4101e5aafc512dc32b8d529b2bafb116a3612de.tar.gz
gcc-a4101e5aafc512dc32b8d529b2bafb116a3612de.tar.bz2
c++: Fix NaN as C++20 template argument
C++20 allows floating-point types for non-type template parameters; floating-point values are considered to be equivalent template arguments if they are "identical", which conveniently seems to map onto an existing GCC predicate. gcc/cp/ChangeLog: * tree.c (cp_tree_equal): Use real_identical. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-float1.C: New test.
-rw-r--r--gcc/cp/tree.c2
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/nontype-float1.C12
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 3c46975..3acb643 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3740,7 +3740,7 @@ cp_tree_equal (tree t1, tree t2)
return tree_int_cst_equal (t1, t2);
case REAL_CST:
- return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
+ return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
case STRING_CST:
return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-float1.C b/gcc/testsuite/g++.dg/cpp2a/nontype-float1.C
new file mode 100644
index 0000000..4fafac1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-float1.C
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++20 } }
+
+#include <cmath>
+
+template<auto> class MyClass { };
+
+static_assert(__is_same(MyClass<NAN>, MyClass<NAN>));
+
+constexpr auto mynan = NAN;
+static_assert(__is_same(MyClass<mynan>, MyClass<mynan>));
+
+static_assert(__is_same(MyClass<NAN>, MyClass<mynan>));