summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp4
-rw-r--r--clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp34
-rw-r--r--clang/test/Preprocessor/has_attribute.cpp2
-rw-r--r--clang/test/Sema/c2x-nodiscard.c6
-rw-r--r--clang/test/SemaCXX/cxx11-attr-print.cpp8
5 files changed, 42 insertions, 12 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
index 4425416650e..45911958af7 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++2a -verify %s
struct [[nodiscard]] S1 {}; // ok
struct [[nodiscard nodiscard]] S2 {}; // expected-error {{attribute 'nodiscard' cannot appear multiple times in an attribute specifier}}
-struct [[nodiscard("Wrong")]] S3 {}; // expected-error {{'nodiscard' cannot have an argument list}}
+struct [[nodiscard("Wrong")]] S3 {};
[[nodiscard]] int f();
enum [[nodiscard]] E {};
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
index 43de9343bd4..9b876086b3e 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -1,5 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++2a -verify -Wc++2a-extensions %s
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify -Wc++17-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -DEXT -Wc++17-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -DEXT -Wc++17-extensions -Wc++2a-extensions %s
struct [[nodiscard]] S {};
S get_s();
@@ -61,10 +62,33 @@ void f() {
}
} // namespace PR31526
+struct [[nodiscard("reason")]] ReasonStruct {};
+struct LaterReason;
+struct [[nodiscard("later reason")]] LaterReason {};
+
+ReasonStruct get_reason();
+LaterReason get_later_reason();
+[[nodiscard("another reason")]] int another_reason();
+
+[[nodiscard("conflicting reason")]] int conflicting_reason();
+[[nodiscard("special reason")]] int conflicting_reason();
+
+void cxx2a_use() {
+ get_reason(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: reason}}
+ get_later_reason(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: later reason}}
+ another_reason(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: another reason}}
+ conflicting_reason(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: special reason}}
+}
+
#ifdef EXT
-// expected-warning@4 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// expected-warning@8 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// expected-warning@11 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@5 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@9 {{use of the 'nodiscard' attribute is a C++17 extension}}
// expected-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@13 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@29 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@65 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@67 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@71 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@73 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@74 {{use of the 'nodiscard' attribute is a C++2a extension}}
#endif
diff --git a/clang/test/Preprocessor/has_attribute.cpp b/clang/test/Preprocessor/has_attribute.cpp
index d35b673e68b..83ee0e3c6cf 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -63,7 +63,7 @@ CXX11(unlikely)
// CHECK: maybe_unused: 201603L
// ITANIUM: no_unique_address: 201803L
// WINDOWS: no_unique_address: 0
-// CHECK: nodiscard: 201603L
+// CHECK: nodiscard: 201907L
// CHECK: noreturn: 200809L
// FIXME(201803L) CHECK: unlikely: 0
diff --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c
index 5eaeda40d9b..cf1f0818419 100644
--- a/clang/test/Sema/c2x-nodiscard.c
+++ b/clang/test/Sema/c2x-nodiscard.c
@@ -6,10 +6,12 @@ struct [[nodiscard]] S1 { // ok
struct [[nodiscard nodiscard]] S2 { // expected-error {{attribute 'nodiscard' cannot appear multiple times in an attribute specifier}}
int i;
};
-struct [[nodiscard("Wrong")]] S3 { // expected-error {{'nodiscard' cannot have an argument list}}
+struct [[nodiscard("Wrong")]] S3 { // FIXME: may need an extension warning.
int i;
};
+struct S3 get_s3(void);
+
[[nodiscard]] int f1(void);
enum [[nodiscard]] E1 { One };
@@ -27,11 +29,13 @@ enum E2 get_e(void);
void f2(void) {
get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ get_s3(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Wrong}}
get_i(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
get_e(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// Okay, warnings are not encouraged
(void)get_s();
+ (void)get_s3();
(void)get_i();
(void)get_e();
}
diff --git a/clang/test/SemaCXX/cxx11-attr-print.cpp b/clang/test/SemaCXX/cxx11-attr-print.cpp
index 12b41758c74..e7c00b76d03 100644
--- a/clang/test/SemaCXX/cxx11-attr-print.cpp
+++ b/clang/test/SemaCXX/cxx11-attr-print.cpp
@@ -37,13 +37,15 @@ void foo() __attribute__((const));
// CHECK: void bar() __attribute__((__const));
void bar() __attribute__((__const));
-// CHECK: int f1() __attribute__((warn_unused_result));
+// FIXME: It's unfortunate that the string literal prints with the below three
+// cases given that the string is only exposed via the [[nodiscard]] spelling.
+// CHECK: int f1() __attribute__((warn_unused_result("")));
int f1() __attribute__((warn_unused_result));
-// CHECK: {{\[}}[clang::warn_unused_result]];
+// CHECK: {{\[}}[clang::warn_unused_result("")]];
int f2 [[clang::warn_unused_result]] ();
-// CHECK: {{\[}}[gnu::warn_unused_result]];
+// CHECK: {{\[}}[gnu::warn_unused_result("")]];
int f3 [[gnu::warn_unused_result]] ();
// FIXME: ast-print need to print C++11
OpenPOWER on IntegriCloud