llvm-capstone/clang/test/SemaCXX/lambda-invalid-capture.cpp
Aaron Ballman 2cb2cd242c Change the behavior of implicit int diagnostics
C89 allowed a type specifier to be elided with the resulting type being
int, aka implicit int behavior. This feature was subsequently removed
in C99 without a deprecation period, so implementations continued to
support the feature. Now, as with implicit function declarations, is a
good time to reevaluate the need for this support.

This patch allows -Wimplicit-int to issue warnings in C89 mode (off by
default), defaults the warning to an error in C99 through C17, and
disables support for the feature entirely in C2x. It also removes a
warning about missing declaration specifiers that really was just an
implicit int warning in disguise and other minor related cleanups.
2022-05-04 08:35:47 -04:00

26 lines
687 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
// Don't crash.
struct g {
j; // expected-error {{a type specifier is required for all declarations}}
};
void captures_invalid_type() {
g child;
auto q = [child]{};
const int n = sizeof(q);
}
void captures_invalid_array_type() {
g child[100];
auto q = [child]{};
const int n = sizeof(q);
}
int pr43080(int i) { // expected-note {{declared here}}
return [] { // expected-note {{begins here}} expected-note 2 {{capture 'i' by}} expected-note 2 {{default capture by}}
return sizeof i <
i; // expected-error {{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
}();
}