Index: include/__config =================================================================== --- include/__config +++ include/__config @@ -900,6 +900,14 @@ #define _LIBCPP_SAFE_STATIC #endif +#ifndef _LIBCPP_NO_DISCARD +# if __has_attribute(warn_unused_result) || _GNUC_VER > 408 +# define _LIBCPP_NO_DISCARD __attribute__((__warn_unused_result__)) +# else +# define _LIBCPP_NO_DISCARD +# endif +#endif // !defined(_LIBCPP_NO_DISCARD) + #if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700 #define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF #endif Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -2768,7 +2768,7 @@ _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __ptr_.first() != nullptr;} - _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT + _LIBCPP_NO_DISCARD _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT { pointer __t = __ptr_.first(); __ptr_.first() = pointer(); @@ -2959,7 +2959,7 @@ _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __ptr_.first() != nullptr;} - _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT + _LIBCPP_NO_DISCARD _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT { pointer __t = __ptr_.first(); __ptr_.first() = pointer(); Index: test/libcxx/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.fail.cpp =================================================================== --- /dev/null +++ test/libcxx/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test release + +#include +#include + +int main() +{ + std::unique_ptr p(new int[3]); + int* i = p.get(); + p.release(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} + delete [] i; +} Index: test/libcxx/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.fail.cpp =================================================================== --- /dev/null +++ test/libcxx/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test release + +#include +#include + +int main() +{ + std::unique_ptr p(new int(3)); + int* i = p.get(); + p.release(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} + delete i; +}