QMCPACK / QMCPACK/qmcpack

QMCPACK antipattern: Throw runtime error if override isn't implemented.

Open
#5,308 3 comments 0 reactions 0 assignees View on GitHub
stale
Dominant language
C++
Stars
403
Forks
154
Avg merge
1d 12h
Merged PRs (30d)
82

Description

`SPOSet::makeClone` is a glaring example of this but I believe it is present many other places as well.

When you want to insure that all derived classes implement a method make it a pure virtual method i.e.
```
/** make a clone of itself
* every derived class must implement this to have threading working correctly.
*/
virtual std::unique_ptr makeClone() const = 0;
```
This causes a compile time error as it should, and gives an immediate explanation. Any error that can be stopped at compile time should be.

_Don't do this_
```
/** make a clone of itself
* every derived class must implement this to have threading working correctly.
*/
[[noreturn]] virtual std::unique_ptr makeClone() const;
```
A runtime error will someday occur hopefully its detailed enough make finding the mplementation that threw it easy, but potentially it will even be seen by a user and not at development time. This is not really a runtime error though is it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.