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.
This commit is contained in:
parent
0251051db6
commit
a4101e5aaf
2 changed files with 13 additions and 1 deletions
|
@ -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)
|
||||
|
|
12
gcc/testsuite/g++.dg/cpp2a/nontype-float1.C
Normal file
12
gcc/testsuite/g++.dg/cpp2a/nontype-float1.C
Normal file
|
@ -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>));
|
Loading…
Add table
Reference in a new issue