Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2025-04-29 21:29:58


Hi Everyone,
I have concerns with the design philosophy of OpenMethod library. Giving
this flexibility that one person can add new open methods to a class
hierarchy in one file and another person can add classes to a class
hierarchy in another file independently, this is asking for
miscommunication problems (programmer bugs) discovered only at runtime.

I tried to recreate this situation that I expect would be common. My first
question, even before I run tests is what will happen when I have a class
hierarchy:

struct Node { virtual ~Node(); };
struct XNode : Node {};

I declare an open method `value()` and override it for XNode in one file,
adn in another file I extend the hierarchy with:

struct YNode : Node {};

And then in main(), in yet another file, I will call `value()` with `YNode`.
The documentation does not give me a clear answer. Section Error Handling
says,

> When an error is encountered, the program is terminated by a call to abort.

And then in the next sentence it talks about different debug and release
policies, and ultimately, I do not know if by default abort() is called or
not.

But that is not the only problem. The docs use the term " When an error is
encountered". What is considered "an error" here? How many situations
constitute "an error"? The docs should enumerate all these situations. I
need to know when my program will be calling `abort()`.

So, I dun a Compiler Explorer test:
https://godbolt.org/z/3fW8j4eTM
And indeed, I get something that looks like abort()

But when I wrap the call into a try-catch block, all of a sudden, the
implementation seems to pick the wrong overrider and return a value,
clearly not the intended one. And the program goes on:
https://godbolt.org/z/Y6z3o56h5

This is the worst thing that can happen: a random runtime behavior. Is this
a bug? Or am I missing something?

Next question that naturally arises: how do I declare `noexcept` open
methods with this library?

Regards,
&rzej;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk