0

I looked through GCC plugin API and some examples on github (which are basic), and I couldn't find anything that could help me with my question.

Suppose that I have a new standard library feature in mind, that can not be implemented with existing C++ features. Is it possible to implement an experimental library feature using GCC plugins?

For example, I would want to implement a function via a compiler extension rather than using additional 3rdparty scripts.

template <typename ... T>
/*result_type*/ aggregate_interfaces(T &...t);

As a result there must be a type, referencing objects t..., and aggregating their public methods using some rule (like not allowing several methods with identical signatures, etc).

Is it possible to implement by the means of GCC Plugins, or the compiler itself needs to be modified?


https://stackoverflow.com/a/8144897/9363996 this answer references an article which seems to be useful

Sergey Kolesnik
  • 3,009
  • 1
  • 8
  • 28
  • 1
    If there's a suitable `operator+` overload, then `(a + b).foo()` should work fine in C++ without the need for compiler extensions. – Some programmer dude Jul 28 '21 at 18:50
  • @Someprogrammerdude I specifically stated, that this is out of the scope. The question is about the possibility to implement a function using the GCC plugins API. So the answer could be at least "yes" or "no". Regarding your solution - it is no better than writing an adapter. It is basically the same - you will have to define/specialize a template class and write all the wrapper methods by hand. – Sergey Kolesnik Jul 28 '21 at 18:55
  • 1
    You have chosen a bad illustration, which will distract people from the gist of your question. Obviously, seasoned C++ developer will balk at the idea of `(a + b).foo() // - is valid, will call a.foo()`, because it just plain wrong and completely violates C++ type system. Your main question about achieving a certain functionality through plugin is valid, so I would suggest removing the whole rationale point and just focus on the question of writing and using gcc plugins. – SergeyA Jul 28 '21 at 19:12
  • 1
    @SergeyA I wish it worked that way. Each time I ask a question without an example, someone will ask about **the reason** to ask this question. You can hardly ever estimate the reaction. – Sergey Kolesnik Jul 28 '21 at 19:21
  • @SergeyKolesnik yes, in some cases when question makes no sense whatsoever, people are trying to understand what is the reason behind it. Some people ask for reason when they simply don't know the answer :). Your question makes sense on it's own and doesn't need motivating example. – SergeyA Jul 28 '21 at 19:30
  • @SergeyA as you might have noticed, I have removed the example. Lets see if it makes any difference... – Sergey Kolesnik Jul 28 '21 at 19:34
  • Probably not, your question is too specific and I imagine majority of SO population would not be familiar with the topic. You might find better luck on gcc specific mailing lists or forums. – SergeyA Jul 28 '21 at 19:40
  • Now this feels kind of like an [XY problem](https://en.wikipedia.org/wiki/XY_problem). You want to implement some new feature by extending C++ though a plugin in GCC. But why? If it's just plain curiosity it's okay and fine, but then please indicate it in the question itself. Otherwise it would help quite a lot if you told us about the actual underlying problem you wanted to solve, presenting the plugin-extension idea as a possible solution. Some smart people (not me) could then perhaps suggest other possible solutions, or otherwise steer you in the right direction for the plugin. – Some programmer dude Jul 28 '21 at 20:06
  • @Someprogrammerdude I did write an example of a problem. And I did state, that I was looking through different solutions. Th most obvious are to write a script that would generate code. Another is to write some complicated template code. Nevertheless, it would really distract from the actual question, which I am interested in regardless. – Sergey Kolesnik Jul 28 '21 at 20:11

0 Answers0