lebedev.ri updated this revision to Diff 152587.
lebedev.ri marked an inline comment as done.
lebedev.ri added a comment.
Herald added a subscriber: llvm-commits.

Right, sorry. Let's try to revive this.
Does this test coverage look better?
What did i miss?


Repository:
  rL LLVM

https://reviews.llvm.org/D45179

Files:
  include/__config
  test/libcxx/diagnostics/disable_nodiscard_aftercxx17.fail.cpp
  test/libcxx/diagnostics/disable_nodiscard_aftercxx17.pass.cpp
  test/libcxx/diagnostics/force_nodiscard.fail.cpp
  test/libcxx/diagnostics/force_nodiscard_disabled.fail.cpp
  test/libcxx/diagnostics/force_nodiscard_disabled.pass.cpp
  test/libcxx/diagnostics/nodiscard.fail.cpp
  test/libcxx/diagnostics/nodiscard.pass.cpp
  test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp

Index: test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp
===================================================================
--- test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp
+++ test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp
@@ -16,9 +16,10 @@
 
 #include <__config>
 
-_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; }
+_LIBCPP_NODISCARD int foo() { return 6; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 6; }
 
-int main ()
-{
-	foo();	// expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+int main() {
+  foo(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+  bar(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: test/libcxx/diagnostics/force_nodiscard_disabled.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/diagnostics/force_nodiscard_disabled.pass.cpp
@@ -0,0 +1,24 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 overrides
+// _LIBCPP_FORCE_NODISCARD define, always.
+
+// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD
+#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#define _LIBCPP_FORCE_NODISCARD
+#include <__config>
+
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 7; }
+
+int main() {
+  bar(); // no error here!
+}
Index: test/libcxx/diagnostics/force_nodiscard_disabled.fail.cpp
===================================================================
--- /dev/null
+++ test/libcxx/diagnostics/force_nodiscard_disabled.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 overrides
+// _LIBCPP_NODISCARD_AFTER_CXX17 define, always.
+// But not the _LIBCPP_NODISCARD.
+
+// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD
+#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#define _LIBCPP_FORCE_NODISCARD
+#include <__config>
+
+_LIBCPP_NODISCARD int foo() { return 6; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 7; }
+
+int main() {
+  foo(); // expected-error {{ignoring return value of function declared with}}
+  bar(); // no error here!
+}
Index: test/libcxx/diagnostics/force_nodiscard.fail.cpp
===================================================================
--- /dev/null
+++ test/libcxx/diagnostics/force_nodiscard.fail.cpp
@@ -0,0 +1,30 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that _LIBCPP_FORCE_NODISCARD always enables nodiscard, regardless of
+// the standard version.
+
+// REQUIRES: clang || apple-clang
+
+// This won't work in gcc before c++17.
+
+// MODULES_DEFINES: _LIBCPP_FORCE_NODISCARD
+#define _LIBCPP_FORCE_NODISCARD
+#include <__config>
+
+_LIBCPP_NODISCARD int foo() { return 6; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 7; }
+
+int main() {
+  foo(); // expected-error {{ignoring return value of function declared with}}
+  bar(); // expected-error {{ignoring return value of function declared with}}
+  // The actual attribute used may be different, so it should not be
+  // specified, or the test will spuriously fail.
+}
Index: test/libcxx/diagnostics/disable_nodiscard_aftercxx17.pass.cpp
===================================================================
--- test/libcxx/diagnostics/disable_nodiscard_aftercxx17.pass.cpp
+++ test/libcxx/diagnostics/disable_nodiscard_aftercxx17.pass.cpp
@@ -19,7 +19,6 @@
 
 _LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; }
 
-int main ()
-{
-	foo();	// no error here!
+int main() {
+  foo(); // no error here!
 }
Index: test/libcxx/diagnostics/disable_nodiscard_aftercxx17.fail.cpp
===================================================================
--- /dev/null
+++ test/libcxx/diagnostics/disable_nodiscard_aftercxx17.fail.cpp
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that _LIBCPP_NODISCARD_AFTER_CXX17 does not affect _LIBCPP_NODISCARD.
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#include <__config>
+
+_LIBCPP_NODISCARD int foo() { return 6; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 7; }
+
+int main() {
+  foo(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+  bar(); // no error here!
+}
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -1015,8 +1015,23 @@
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX17
 #endif
 
+// NOTE: Do not use [[nodiscard]] in pre-C++17 mode
+//       to avoid -Wc++17-extensions warning.
+// And we can't use GCC's [[gnu::warn_unused_result]] and
+// __attribute__((warn_unused_result)),
+// because GCC does not silence them via (void) cast.
+#if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER >= 17
+#  define _LIBCPP_NODISCARD [[nodiscard]]
+#elif __has_cpp_attribute(clang::warn_unused_result)
+#  define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
+#else
+#  define _LIBCPP_NODISCARD
+#endif
+
 #if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17)
 #  define _LIBCPP_NODISCARD_AFTER_CXX17 [[nodiscard]]
+#elif !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && defined(_LIBCPP_FORCE_NODISCARD)
+#  define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
 #else
 #  define _LIBCPP_NODISCARD_AFTER_CXX17
 #endif
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to