summaryrefslogtreecommitdiff
path: root/test/libcxx/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'test/libcxx/diagnostics')
-rw-r--r--test/libcxx/diagnostics/enable_nodiscard.fail.cpp33
-rw-r--r--test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.fail.cpp33
-rw-r--r--test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.fail.cpp31
-rw-r--r--test/libcxx/diagnostics/nodiscard.pass.cpp15
-rw-r--r--test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp (renamed from test/libcxx/diagnostics/nodiscard.fail.cpp)1
-rw-r--r--test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp23
-rw-r--r--test/libcxx/diagnostics/nodiscard_extensions.fail.cpp35
-rw-r--r--test/libcxx/diagnostics/nodiscard_extensions.pass.cpp29
8 files changed, 189 insertions, 11 deletions
diff --git a/test/libcxx/diagnostics/enable_nodiscard.fail.cpp b/test/libcxx/diagnostics/enable_nodiscard.fail.cpp
new file mode 100644
index 000000000000..e1ef17672ccb
--- /dev/null
+++ b/test/libcxx/diagnostics/enable_nodiscard.fail.cpp
@@ -0,0 +1,33 @@
+// -*- 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_EXT and _LIBCPP_NODISCARD_AFTER_CXX17 are defined
+// to the appropriate warning-generating attribute when _LIBCPP_ENABLE_NODISCARD
+// is explicitly provided.
+
+// UNSUPPORTED: c++98, c++03
+
+// GCC 7 is the first version to introduce [[nodiscard]]
+// UNSUPPORTED: gcc-4.9, gcc-5, gcc-6
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_NODISCARD
+#define _LIBCPP_ENABLE_NODISCARD
+
+#include <__config>
+
+_LIBCPP_NODISCARD_EXT int foo() { return 42; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 42; }
+
+int main() {
+ foo(); // expected-error-re {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ bar(); // expected-error-re {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ (void)foo(); // OK. void casts disable the diagnostic.
+ (void)bar();
+}
diff --git a/test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.fail.cpp b/test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.fail.cpp
new file mode 100644
index 000000000000..2c7d899ff5a0
--- /dev/null
+++ b/test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.fail.cpp
@@ -0,0 +1,33 @@
+// -*- 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// GCC 7 is the first version to introduce [[nodiscard]]
+// UNSUPPORTED: gcc-4.9, gcc-5, gcc-6
+
+// Test that _LIBCPP_DISABLE_NODISCARD_EXT only disables _LIBCPP_NODISCARD_EXT
+// and not _LIBCPP_NODISCARD_AFTER_CXX17.
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_NODISCARD
+// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#define _LIBCPP_ENABLE_NODISCARD
+#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#include <__config>
+
+
+_LIBCPP_NODISCARD_EXT int foo() { return 42; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 42; }
+
+int main() {
+ foo(); // expected-error-re {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ bar(); // OK.
+ (void)foo(); // OK.
+}
diff --git a/test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.fail.cpp b/test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.fail.cpp
new file mode 100644
index 000000000000..c7d080d8425c
--- /dev/null
+++ b/test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.fail.cpp
@@ -0,0 +1,31 @@
+// -*- 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// GCC 7 is the first version to introduce [[nodiscard]]
+// UNSUPPORTED: gcc-4.9, gcc-5, gcc-6
+
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_NODISCARD
+// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_EXT
+#define _LIBCPP_ENABLE_NODISCARD
+#define _LIBCPP_DISABLE_NODISCARD_EXT
+#include <__config>
+
+
+_LIBCPP_NODISCARD_EXT int foo() { return 42; }
+_LIBCPP_NODISCARD_AFTER_CXX17 int bar() { return 42; }
+
+int main() {
+ bar(); // expected-error-re {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ foo(); // OK.
+ (void)bar(); // OK.
+}
diff --git a/test/libcxx/diagnostics/nodiscard.pass.cpp b/test/libcxx/diagnostics/nodiscard.pass.cpp
index d308248cff22..de920d459ed6 100644
--- a/test/libcxx/diagnostics/nodiscard.pass.cpp
+++ b/test/libcxx/diagnostics/nodiscard.pass.cpp
@@ -8,18 +8,13 @@
//
//===----------------------------------------------------------------------===//
-// Test that _LIBCPP_NODISCARD_AFTER_CXX17 works
-// #define _LIBCPP_NODISCARD_AFTER_CXX17 [[nodiscard]]
+// Test that _LIBCPP_NODISCARD_EXT is not defined to [[nodiscard]] unless
+// explicitly enabled by _LIBCPP_ENABLE_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_AFTER_CXX17 int foo() { return 6; }
+_LIBCPP_NODISCARD_EXT int foo() { return 42; }
-int main ()
-{
- foo(); // no error here!
+int main() {
+ foo(); // OK.
}
diff --git a/test/libcxx/diagnostics/nodiscard.fail.cpp b/test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp
index 903a24a72805..47e560feb962 100644
--- a/test/libcxx/diagnostics/nodiscard.fail.cpp
+++ b/test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp
@@ -12,7 +12,6 @@
// #define _LIBCPP_NODISCARD_AFTER_CXX17 [[nodiscard]]
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
-// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
#include <__config>
diff --git a/test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp b/test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp
new file mode 100644
index 000000000000..4db8181723e1
--- /dev/null
+++ b/test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp
@@ -0,0 +1,23 @@
+// -*- 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 is disabled whenever
+// _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 is defined by the user.
+
+// MODULES_DEFINES: _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#define _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17
+#include <__config>
+
+_LIBCPP_NODISCARD_AFTER_CXX17 int foo() { return 6; }
+
+int main ()
+{
+ foo(); // no error here!
+}
diff --git a/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp b/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp
new file mode 100644
index 000000000000..d1e0a8af5c8a
--- /dev/null
+++ b/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp
@@ -0,0 +1,35 @@
+// -*- 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// GCC versions prior to 7.0 don't provide the required [[nodiscard]] attribute.
+// UNSUPPORTED: gcc-4, gcc-5, gcc-6
+
+// Test that entities declared [[nodiscard]] as at extension by libc++, are
+// only actually declared such when _LIBCPP_ENABLE_NODISCARD is specified.
+
+// All entities to which libc++ applies [[nodiscard]] as an extension should
+// be tested here and in nodiscard_extensions.pass.cpp. They should also
+// be listed in `UsingLibcxx.rst` in the documentation for the extension.
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_NODISCARD
+#define _LIBCPP_ENABLE_NODISCARD
+
+#include <memory>
+
+#include "test_macros.h"
+
+int main() {
+ {
+ // expected-error-re@+1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::get_temporary_buffer<int>(1);
+ }
+}
diff --git a/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp b/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp
new file mode 100644
index 000000000000..9a09a43bae1c
--- /dev/null
+++ b/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp
@@ -0,0 +1,29 @@
+// -*- 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 entities declared [[nodiscard]] as at extension by libc++, are
+// only actually declared such when _LIBCPP_ENABLE_NODISCARD is specified.
+
+// This test intentionally leaks memory, so it is unsupported under ASAN.
+// UNSUPPORTED: asan
+
+// All entities to which libc++ applies [[nodiscard]] as an extension should
+// be tested here and in nodiscard_extensions.fail.cpp. They should also
+// be listed in `UsingLibcxx.rst` in the documentation for the extension.
+
+#include <memory>
+
+#include "test_macros.h"
+
+int main() {
+ {
+ std::get_temporary_buffer<int>(1); // intentional memory leak.
+ }
+}