arguments. There are two aspects to this: - Make sure that when marking the declarations referenced in a default argument, we don't try to mark local variables, both because it's a waste of time and because the semantics are wrong: we're not in a place where we could capture these variables again even if it did make sense. - When a lambda expression occurs in a default argument of a function template, make sure that the corresponding closure type is considered dependent, so that it will get properly instantiated. The second bit is a bit of a hack; to fix it properly, we may have to rearchitect our handling of default arguments, parsing them only after creating the function definition. However, I'd like to separate that work from the lambdas work. llvm-svn: 151076
17 lines
721 B
C++
17 lines
721 B
C++
// RUN: %clang_cc1 -std=c++11 %s -Wunused -verify
|
|
|
|
void f2() {
|
|
int i = 1;
|
|
void g1(int = ([i]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
|
|
void g2(int = ([i]{ return 0; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
|
|
void g3(int = ([=]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
|
|
void g4(int = ([=]{ return 0; })());
|
|
void g5(int = ([]{ return sizeof i; })());
|
|
}
|
|
|
|
namespace lambda_in_default_args {
|
|
int f(int = [] () -> int { int n; return ++n; } ());
|
|
template<typename T> T g(T = [] () -> T { T n; return ++n; } ());
|
|
int k = f() + g<int>();
|
|
}
|