Jordan Rupprecht 74ce297045 Revert "[Clang] Implement Change scope of lambda trailing-return-type"
This reverts commit d708a186b6a9b050d09558163dd353d9f738c82d (and typo fix e4bc9898ddbeb70bc49d713bbf863f050f21e03f). It causes a compilation error for this:

```
struct StringLiteral {
  template <int N>
  StringLiteral(const char (&array)[N])
      __attribute__((enable_if(N > 0 && N == __builtin_strlen(array) + 1,
                               "invalid string literal")));
};

struct Message {
  Message(StringLiteral);
};

void Func1() {
  auto x = Message("x");  // Note: this is fine

  // Note: "xx\0" to force a different type, StringLiteral<3>, otherwise this
  // successfully builds.
  auto y = [&](decltype(Message("xx"))) {};

  // ^ fails with: repro.cc:18:13: error: reference to local variable 'array'
  // declared in enclosing function 'StringLiteral::StringLiteral<3>'

  (void)x;
  (void)y;
}
```

More details posted to D124351.
2023-02-03 08:49:34 -08:00

53 lines
1.1 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify -DCPP1Y
void missing_lambda_declarator() {
[](){}();
}
template<typename T> T get();
void infer_void_return_type(int i) {
if (i > 17)
return []() { }();
if (i > 11)
return []() { return; }();
return [](int x) {
switch (x) {
case 0: return get<void>();
case 1: return;
case 2: return { 1, 2.0 }; //expected-error{{cannot deduce}}
}
}(7);
}
struct X { };
X infer_X_return_type(X x) {
return [&x](int y) {
if (y > 0)
return X();
else
return x;
}(5);
}
X infer_X_return_type_2(X x) {
return [x](int y) {
if (y > 0)
return X();
else
return x; // ok even in c++11, per dr1048.
}(5);
}
struct Incomplete; // expected-note{{forward declaration of 'Incomplete'}}
void test_result_type(int N) {
auto l1 = [] () -> Incomplete { }; // expected-error{{incomplete result type 'Incomplete' in lambda expression}}
typedef int vla[N];
auto l2 = [] () -> vla { }; // expected-error{{function cannot return array type 'vla' (aka 'int[N]')}}
}