C++ Logo

sg7

Advanced search

Re: Attributes introspection

From: Jean-Baptiste Vallon Hoarau <jeanbaptiste.vallon_at_[hidden]>
Date: Wed, 24 Apr 2024 14:33:47 +0200
The problem is that `logInvoke` is passed a pointer to the function at
run-time, so this cannot work, reflection or not, because the only thing
you can reflect on in that case is the type of the function. Even if
`logInvoke` was consteval (which makes no sense for a logging function but
let's pretend) you'd need 1/ something to retrieve the declaration from the
pointer value 2/ reflection on attributes 3/ a way to emit arbitrary
diagnostics.

I think a function is not the best tool to log a call, given that you
couldn't even retrieve the name of the function being called (again,
reflection or not).
This might be a good time to talk about the reflection prototype I've
developed, implementing a `logInvoke` macro with it is pretty
straightforward :
https://cppmeta.codereckons.com/tools/z/jPjrrq

It's a bit verbose as you can see (the parens around the injected
expression should not be needed anymore in the near future), but it works.



Le mer. 24 avr. 2024 à 14:08, Aurelien Cassagnes <
aurelien.cassagnes_at_[hidden]> a écrit :

> I know attributes arent part of the type otherwise we’d be more or less
> done with decltype…
>
> Toy example fwiw public is not distinct from private function as far as
> typing system is concerned, but this level of info is proposed to be made
> available via metafunctions in the reflection paper.
>
> Now if someone did try to fork and implement this proposal and came back
> with arguments for why this just cant ever be done , we can put this to
> rest.
>
> Sent from Gmail Mobile
>
>
> On Wed, Apr 24, 2024 at 20:30 Jean-Baptiste Vallon Hoarau <
> jeanbaptiste.vallon_at_[hidden]> wrote:
>
>> What Barry was saying is that this cannot work : templates are
>> instantiated per type, and the attributes are not part of the type, so the
>> information is simply not passed down to the instantiation of the template,
>> reflection or not.
>>
>> Le mer. 24 avr. 2024 à 13:26, Aurelien Cassagnes via SG7 <
>> sg7_at_[hidden]> a écrit :
>>
>>> Barry I understand that right now there is no reasons for it to work,
>>> the purpose of this thread is to flesh out what the proposal look like.
>>> Gather interest and feedback not share an hypothetical implementation
>>> because it doesnt exist yet.
>>>
>>> Besides seeing interest, the feedback i’m interested is what sections
>>> need to be discussed in more detail in the draft for it to become more
>>> meaningful
>>> thanks.
>>>
>>> Sent from Gmail Mobile
>>>
>>>
>>> On Sun, Apr 21, 2024 at 1:47 Barry Revzin <barry.revzin_at_[hidden]>
>>> wrote:
>>>
>>>>
>>>>
>>>> On Fri, Apr 19, 2024, 9:53 PM Aurelien Cassagnes via SG7 <
>>>> sg7_at_[hidden]> wrote:
>>>>
>>>>> Fleshed out the proposal draft and it's available for feedback at
>>>>> https://github.com/zebullax/wg21/blob/main/generated/proposal.pdf
>>>>>
>>>>
>>>> How do you expect this to work exactly?
>>>>
>>>> The type of foo is bool(int), it's not [[nodiscard]] bool(int).
>>>> Regardless of the question of reflecting on attributes... logInvoke(foo, 0)
>>>> is going to call logInvoke<bool(int), int>. There aren't any attributes
>>>> left to reflect on anymore.
>>>>
>>>> Barry
>>>>
>>>>> --
>>>
>> SG7 mailing list
>>> SG7_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/sg7
>>>
>>

Received on 2024-04-24 12:34:04