mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
Compare reflections of REAL_CST using cp_tree_equal.
This commit is contained in:
committed by
Marek Polacek
parent
873b436943
commit
9444292934
@@ -8104,16 +8104,26 @@ compare_reflections (tree lhs, tree rhs)
|
||||
&& tree_int_cst_equal (TREE_VEC_ELT (lhs, 3),
|
||||
TREE_VEC_ELT (rhs, 3))
|
||||
&& TREE_VEC_ELT (lhs, 4) == TREE_VEC_ELT (rhs, 4));
|
||||
/* Sometimes the ARRAY_REFs differ only in that one has a location
|
||||
and the other doesn't. ??? Maybe strip the location and fall back
|
||||
to ==? */
|
||||
else if (TREE_CODE (lhs) == ARRAY_REF && TREE_CODE (rhs) == ARRAY_REF)
|
||||
return (TREE_TYPE (lhs) == TREE_TYPE (rhs)
|
||||
&& TREE_OPERAND (lhs, 0) == TREE_OPERAND (rhs, 0)
|
||||
&& TREE_OPERAND (lhs, 1) == TREE_OPERAND (rhs, 1)
|
||||
&& TREE_OPERAND (lhs, 2) == TREE_OPERAND (rhs, 2));
|
||||
|
||||
return lhs == rhs;
|
||||
if (lhs == rhs)
|
||||
return true;
|
||||
|
||||
/* Some trees are not shared. */
|
||||
if (TREE_CODE (lhs) == TREE_CODE (rhs))
|
||||
switch (TREE_CODE (lhs))
|
||||
{
|
||||
case ARRAY_REF:
|
||||
return (TREE_TYPE (lhs) == TREE_TYPE (rhs)
|
||||
&& TREE_OPERAND (lhs, 0) == TREE_OPERAND (rhs, 0)
|
||||
&& TREE_OPERAND (lhs, 1) == TREE_OPERAND (rhs, 1)
|
||||
&& TREE_OPERAND (lhs, 2) == TREE_OPERAND (rhs, 2));
|
||||
case REAL_CST:
|
||||
return cp_tree_equal (lhs, rhs);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Return true if T is a valid splice-type-specifier.
|
||||
|
||||
30
gcc/testsuite/g++.dg/reflect/annotations5.C
Normal file
30
gcc/testsuite/g++.dg/reflect/annotations5.C
Normal file
@@ -0,0 +1,30 @@
|
||||
// C++ 26 P3394R4 - Annotations for Reflection
|
||||
// { dg-do compile { target c++26 } }
|
||||
// { dg-additional-options "-freflection" }
|
||||
// Test std::meta::annotations_of.
|
||||
|
||||
#include <meta>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
[[=1, =1, =2, =1.0f]] void foo ();
|
||||
static_assert ((std::meta::annotations_of (^^foo)
|
||||
| std::views::transform (std::meta::constant_of)
|
||||
| std::ranges::to<std::vector> ())
|
||||
== std::vector { std::meta::reflect_constant (1),
|
||||
std::meta::reflect_constant (1),
|
||||
std::meta::reflect_constant (2),
|
||||
std::meta::reflect_constant (1.0f) });
|
||||
|
||||
[[=1]] [[=2]] void bar ();
|
||||
[[=3]] [[=3]] void bar ();
|
||||
[[=4L, =42]] void bar ();
|
||||
static_assert ((std::meta::annotations_of (^^bar)
|
||||
| std::views::transform (std::meta::constant_of)
|
||||
| std::ranges::to<std::vector> ())
|
||||
== std::vector { std::meta::reflect_constant (1),
|
||||
std::meta::reflect_constant (2),
|
||||
std::meta::reflect_constant (3),
|
||||
std::meta::reflect_constant (3),
|
||||
std::meta::reflect_constant (4L),
|
||||
std::meta::reflect_constant (42) });
|
||||
Reference in New Issue
Block a user