Files
clang-p2996/clang/test/Parser/objcxx11-attributes.mm
Yuanfang Chen 27a972a699 Diagnose -Wunused-value based on CFG reachability
(This relands 59337263ab and makes sure comma operator
 diagnostics are suppressed in a SFINAE context.)

While at it, add the diagnosis message "left operand of comma operator has no effect" (used by GCC) for comma operator.

This also makes Clang diagnose in the constant evaluation context which aligns with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96)

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D103938
2021-09-28 10:00:15 -07:00

67 lines
2.6 KiB
Plaintext

// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
@interface X {}
+ (X*) alloc;
- (X*) init;
- (int) getSize;
- (void) setSize: (int) size;
- (X*) getSelf;
@end
void f(X *noreturn) {
// An array size which is computed by a message send is OK.
int a[ [noreturn getSize] ];
// ... but is interpreted as an attribute where possible.
int b[ [noreturn] ]; // expected-error {{'noreturn' attribute only applies to functions}}
int c[ [noreturn getSize] + 1 ];
// An array size which is computed by a lambda is not OK.
int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-error {{'noreturn' attribute only applies to functions}}
// A message send which contains a message send is OK.
[ [ X alloc ] init ];
[ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{left operand of comma operator has no effect}}
// A message send which contains a lambda is OK.
[ [noreturn] { return noreturn; } () setSize: 4 ];
[ [bitand] { return noreturn; } () setSize: 5 ];
[[[[] { return [ X alloc ]; } () init] getSelf] getSize];
// An attribute is OK.
[[]];
[[int(), noreturn]]; // expected-warning {{unknown attribute 'int' ignored}} \
// expected-error {{'noreturn' attribute cannot be applied to a statement}}
[[class, test(foo 'x' bar),,,]]; // expected-warning {{unknown attribute 'test' ignored}}\
// expected-warning {{unknown attribute 'class' ignored}}
[[bitand, noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a statement}} \
expected-warning {{unknown attribute 'bitand' ignored}}
// FIXME: Suppress vexing parse warning
[[gnu::noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}}
// A function taking a noreturn function.
int(f)([[gnu::noreturn]] int ()); // expected-note {{here}}
f(e);
f(e2); // expected-error {{cannot initialize a parameter of type 'int (*)() __attribute__((noreturn))' with an lvalue of type 'int ()'}}
// Variables initialized by a message send.
int(g)([[noreturn getSelf] getSize]);
int(h)([[noreturn]{return noreturn;}() getSize]);
int i = g + h;
}
template<typename...Ts> void f(Ts ...x) {
[[test::foo(bar, baz)...]]; // expected-error {{attribute 'foo' cannot be used as an attribute pack}} \
// expected-warning {{unknown attribute 'foo' ignored}}
[[used(x)...]]; // expected-error {{attribute 'used' cannot be used as an attribute pack}} \
// expected-warning {{unknown attribute 'used' ignored}}
[[x...] { return [ X alloc ]; }() init];
}