Skip to content

Checking in Field constructors #1361

Description

@ZedThree

Currently, there's lots of checking via calls to checkData all over the place, and I wonder if it's possible to remove some of them. Take the following example:

Field3D f, a{0.0}, b{a};

f = (a + 1) * b;

There are seven calls to checkData(Field3D) (one in the copy ctor for b, two in the addition, three in the multiplication, one in the assignment) and two to checkData(BoutReal) (one in the initialisation of a, one in addition).

I would like to remove the checkData(Field3D) from the copy-constructor and -assignment operator. This would allow e.g. making them both noexcept. We've got much better at pre- and post-conditions in Field operations so I think it would be ok to relax them in copy construction/assignment.

A potential downside would be not catching the following situations:

Field3D a, b{a};
// or
void foo(Field3D f);
Field3D c;
foo(c);

I think the first case is probably too rare to worry about and would be caught as soon you tried to use b.
The second case is likely also very rare -- we normally don't pass Fields by value, and this could be solved by calling checkData(f) immediately inside foo anyway (which we should be doing!).

See e.g. #914 for a related issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions