// A warning group for warnings about code that clang accepts when
// compiling CUDA C/C++ but which is not compatible with the CUDA spec.
def CudaCompat : DiagGroup<"cuda-compat">;
+
+// A warning group for things that will change semantics in the future.
+def FutureCompat : DiagGroup<"future-compat">;
def err_lambda_missing_parens : Error<
"lambda requires '()' before %select{'mutable'|return type|"
"attribute specifier}0">;
+def warn_init_capture_direct_list_init : Warning<
+ "direct list initialization of a lambda init-capture will change meaning in "
+ "a future version of Clang; insert an '=' to avoid a change in behavior">,
+ InGroup<FutureCompat>;
// Availability attribute
def err_expected_version : Error<
def err_auto_var_init_paren_braces : Error<
"cannot deduce type for variable %0 with type %1 from "
"parenthesized initializer list">;
+def warn_auto_var_direct_list_init : Warning<
+ "direct list initialization of a variable with a deduced type will change "
+ "meaning in a future version of Clang; insert an '=' to avoid a change in "
+ "behavior">, InGroup<FutureCompat>;
def err_auto_new_ctor_multiple_expressions : Error<
"new expression for type %0 contains multiple constructor arguments">;
def err_auto_missing_trailing_return : Error<
// to save the necessary state, and restore it later.
EnterExpressionEvaluationContext EC(Actions,
Sema::PotentiallyEvaluated);
- TryConsumeToken(tok::equal);
+ bool HadEquals = TryConsumeToken(tok::equal);
- if (!SkippedInits)
+ if (!SkippedInits) {
+ // Warn on constructs that will change meaning when we implement N3922
+ if (!HadEquals && Tok.is(tok::l_brace)) {
+ Diag(Tok, diag::warn_init_capture_direct_list_init)
+ << FixItHint::CreateInsertion(Tok.getLocation(), "=");
+ }
Init = ParseInitializer();
- else if (Tok.is(tok::l_brace)) {
+ } else if (Tok.is(tok::l_brace)) {
BalancedDelimiterTracker Braces(*this, tok::l_brace);
Braces.consumeOpen();
Braces.skipToEnd();
CheckVariableDeclarationType(VDecl);
if (VDecl->isInvalidDecl())
return;
+
+ // If all looks well, warn if this is a case that will change meaning when
+ // we implement N3922.
+ if (DirectInit && !CXXDirectInit && isa<InitListExpr>(Init)) {
+ Diag(Init->getLocStart(),
+ diag::warn_auto_var_direct_list_init)
+ << FixItHint::CreateInsertion(Init->getLocStart(), "=");
+ }
}
// dllimport cannot be used on variable definitions.
auto bad_init_3 = [&a(void_fn())] {}; // expected-error {{cannot form a reference to 'void'}}
auto bad_init_4 = [a(void_fn())] {}; // expected-error {{has incomplete type 'void'}}
auto bad_init_5 = [a(overload_fn)] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer of type '<overloaded function}}
-auto bad_init_6 = [a{overload_fn}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer list}}
+auto bad_init_6 = [a{overload_fn}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer list}} expected-warning {{will change meaning in a future version of Clang}}
template<typename...T> void pack_1(T...t) { (void)[a(t...)] {}; } // expected-error {{initializer missing for lambda capture 'a'}}
template void pack_1<>(); // expected-note {{instantiation of}}
using T = decltype(c);
using T = const int &;
};
-auto b = [a{0}] {}; // expected-error {{include <initializer_list>}}
+auto b = [a{0}] {}; // expected-error {{include <initializer_list>}} expected-warning {{will change meaning in a future version of Clang}}
struct S { S(); S(S&&); };
template<typename T> struct remove_reference { typedef T type; };
int z;
void init_capture() {
[n(0)] () mutable -> int { return ++n; }; // expected-warning{{extension}}
- [n{0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}}
+ [n{0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}} expected-warning{{will change meaning in a future version}}
[n = 0] { return ++n; }; // expected-error {{captured by copy in a non-mutable}} expected-warning{{extension}}
[n = {0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}}
[a([&b = z]{})](){}; // expected-warning 2{{extension}}
[foo(bar)] () {};
[foo = bar] () {};
- [foo{bar}] () {}; // expected-error {{<initializer_list>}}
+ [foo{bar}] () {}; // expected-error {{<initializer_list>}} expected-warning {{will change meaning}}
[foo = {bar}] () {}; // expected-error {{<initializer_list>}}
[foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}}
void auto_deduction() {
auto l = {1, 2, 3, 4};
+ auto l2 {1, 2, 3, 4}; // expected-warning {{will change meaning in a future version of Clang}}
static_assert(same_type<decltype(l), std::initializer_list<int>>::value, "");
auto bl = {1, 2.0}; // expected-error {{cannot deduce}}