Use C10_HAS_CPP_ATTRIBUTE to simplify nodiscard definition (#83976)
`C10_HAS_CPP_ATTRIBUTE` only expands to `__has_cpp_attribute` when it
is defined, so we avoid the extra `#if defined(__has_cpp_attribute)`
checks and double-nested `#if`s
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83976
Approved by: https://github.com/albanD