Merge branch 'fix-stack-overflow' into 'master'

Fix some stack overflows caused by recursion with identical arguments/state.

See merge request !5
6 jobs for master in 6 minutes and 56 seconds (queued for 1 second)
Status Job ID Name Coverage
  Build
passed #109475
Linux
clang-c++11

00:03:20

passed #109480
Linux
clang-c++14

00:06:45

passed #109473
Linux
gcc-c++11

00:02:14

passed #109477
Linux
gcc-c++14

00:01:44

passed #109482
Apple
macos-c++11

00:02:50

passed #109483
Apple
macos-c++14

00:05:17