Surprisingly "declare XXX=$(false);echo $?" outputs "0" (not "1") There is no indication in the manual page that "declare" ignores the exit code of commands being executed to set values. Actually I's consider it to be a ASH bug, not a documentation bug.
Found in the real code (intended to trigger a bug): declare ERRORS=0 ARGS=$(getopt -o "$S_OPTS" -l "$L_OPTS" -n "$0" -- "$@") if [ $? -ne 0 ]; then usage fi ++ getopt -o e:i:v -l exclude:,include:,verbose -n ./buggy.sh -- add -vv -iHCTL_DEFS -k SAPDA_DEFS -- -p ./buggy.sh: invalid option -- 'k' + declare ERRORS=0 'ARGS= -v -v -i '\''HCTL_DEFS'\'' -- '\''add'\'' '\''SAPDA_DEFS'\'' '\''-p'\''' + '[' 0 -ne 0 ']'