#attributes
2 posts tagged #attributes.
MSVC ignores a [[nodiscard]] written after static, and /W4 says nothing
static [[nodiscard]] int f() compiles on MSVC at /W4 with no diagnostic, and a discarded call goes unreported. On Compiler Explorer, four MSVC builds from 19.30 to 19.51 do this for all eight keywords a reader listed. GCC and Clang reject the form. /we5240 turns it into an error.
Clang's lifetimebound warns about a copy, and that is the problem
The lifetimebound attribute lets -Wdangling see through a function call, which is how clang catches a string_view into a temporary. It has no conditional form, so a function that returns a copy on some instantiations and a reference on others has to pick between missing real dangles and warning about correct code. A proposal on the LLVM forum wants to close that gap.