Skip to content

Commit d6ac2b2

Browse files
committed
added tests for make_unique/make_shared nodiscard attribute
1 parent d793dae commit d6ac2b2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14
10+
11+
// check that functions are marked [[nodiscard]] as an extension in C++17
12+
13+
// [[nodiscard]] std::make_unique(Args&&...);
14+
// [[nodiscard]] std::make_shared(Args&&...);
15+
//
16+
// [[nodiscard]] std::make_unique(size_t);
17+
// [[nodiscard]] std::make_shared(size_t);
18+
//
19+
// [[nodiscard]] std::make_unique_for_overwrite();
20+
// [[nodiscard]] std::make_shared_for_overwrite();
21+
22+
#include <memory>
23+
24+
void f() {
25+
26+
struct S {
27+
S() = default;
28+
};
29+
30+
std::make_unique<S>(S{}); // expected-warning {{ignoring return value of function}}
31+
std::make_shared<S>(S{}); // expected-warning {{ignoring return value of function}}
32+
33+
std::make_unique<S[]>(5); // expected-warning {{ignoring return value of function}}
34+
std::make_shared<S[]>(5); // expected-warning {{ignoring return value of function}}
35+
36+
std::make_unique_for_overwrite<S>(); // expected-warning {{ignoring return value of function}}
37+
std::make_shared_for_overwrite<S>(); // expected-warning {{ignoring return value of function}}
38+
39+
}

0 commit comments

Comments
 (0)