-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc++] Add nodiscard attribute to std::make_unique/std::make_shared #153115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
935d246
30e0103
cf7c589
2a26cb8
e13ed16
b229542
1ae47c2
cb4d239
710f97c
d793dae
d6ac2b2
23356ef
2e14fa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14 | ||
|
||
// check that functions are marked [[nodiscard]] as an extension in C++17 | ||
|
||
// [[nodiscard]] std::make_unique(Args&&...); | ||
// [[nodiscard]] std::make_shared(Args&&...); | ||
// | ||
// [[nodiscard]] std::make_unique(size_t); | ||
// [[nodiscard]] std::make_shared(size_t); | ||
// | ||
// [[nodiscard]] std::make_unique_for_overwrite(); | ||
// [[nodiscard]] std::make_shared_for_overwrite(); | ||
|
||
#include <memory> | ||
|
||
void f() { | ||
|
||
struct S { | ||
S() = default; | ||
}; | ||
lukasx999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::make_unique<S>(S{}); // expected-warning {{ignoring return value of function}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you're missing a few test cases. I count 12 new annotations above, but this tests only 6 functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where do you see 12 annotations? I only see 6. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also counted 12. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry but you're not being very helpful, you do mind pointing me to a resource that explains how "annotations" in this test system work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These I think what @philnik777 is referring to is that you added |
||
std::make_shared<S>(S{}); // expected-warning {{ignoring return value of function}} | ||
|
||
std::make_unique<S[]>(5); // expected-warning {{ignoring return value of function}} | ||
std::make_shared<S[]>(5); // expected-warning {{ignoring return value of function}} | ||
|
||
std::make_unique_for_overwrite<S>(); // expected-warning {{ignoring return value of function}} | ||
std::make_shared_for_overwrite<S>(); // expected-warning {{ignoring return value of function}} | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.