On 9/25/24 12:44 PM, Patrick Palka wrote:
On Wed, 25 Sep 2024, Jason Merrill wrote:
On 7/30/24 6:49 PM, Giuseppe D'Angelo wrote:
On 29/07/2024 22:53, Giuseppe D'Angelo wrote:
Hi,
The attached patch is a stab at adding the necessary compiler builtin to
support std::is_virtual_base_of (P2985R0, approved for C++26). The name
of the builtin matches the one just merged into clang:
https://github.com/llvm/llvm-project/issues/98310
The next patch will add the libstdc++ bits.
Hello,
This is a new revision of the same patch, this time with a DCO.
+ ba_require_virtual = 1 << 3 /* Require a virtual base */
Why change lookup rather than just call lookup_base and then binfo_from_vbase
in trait_expr_value?
IIUC it's because of the ambiguous case: std::is_virtual_base_of needs
to be true if there's an ambiguous virtual base, one of which is virtual,
but lookup_base by default prefers returning a non-virtual base in case
of ambiguity.
Ah, I didn't read far enough in the paper.
Supporting the ambiguous case seems pointless to me but, that is what
the accepted proposal specifies, so indeed that's what we should implement.
+/* Nonzero iff TYPE is derived virtually from PARENT. Ignores accessibility and
+ ambiguity issues. */
+#define DERIVED_VIRTUALLY_FROM_P(PARENT, TYPE) \
+ (lookup_base ((TYPE), (PARENT), ba_require_virtual, NULL, tf_none) !=
NULL_TREE)
I don't think we need a macro for this.
+ ba_require_virtual = 1 << 3 /* Require a virtual base */
Comment should end with period and two spaces.
+ /* Skip this result if we require virtual inheritance
+ and this is not a virtual base. */
Likewise.
- data.want_any = access == ba_any;
+ data.want_any = (access & ~ba_require_virtual) == ba_any;
data.offset = offset;
+ data.require_virtual = (access & ba_require_virtual);
It seems like you aren't using ba_require_virtual|ba_any, so do you need
to mess with bitwise &?
+@defbuiltin{bool __builtin_is_virtual_base_of (@var{base_type},
@var{derived_type})}
+If @var{base_type} is a virtual base class of @var{derived_type}
+([class.derived]) then the trait is @code{true}, otherwise it is @code{false}.
+Top-level cv-qualifications of @var{base_type} and
+@var{derived_type} are ignored.
We might mention here that this ignores access and ambiguity.
Jason