C++ Logo

sg7

Advanced search

Re: Attributes introspection

From: jm <jm_at_[hidden]>
Date: Wed, 24 Apr 2024 15:43:14 +0200
p-- Jean-Marc Bourguet
-------- Message d'origine --------De : Jean-Baptiste Vallon Hoarau via SG7 <sg7_at_[hidden]> Date : 24/04/2024 14:34 (GMT+01:00) À : Aurelien Cassagnes <aurelien.cassagnes_at_[hidden]> Cc : Jean-Baptiste Vallon Hoarau <jeanbaptiste.vallon_at_[hidden]>, sg7_at_[hidden] Objet : Re: [SG7] Attributes introspection 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/jPjrrqIt'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 MobileOn 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 meaningfulthanks. Sent from Gmail MobileOn 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.pdfHow 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 13:43:24