teak-llvm/clang/test/CodeGenCXX/PR28523.cpp
Alexey Bataev 31939e39db Fix for PR28523: unexpected compilation error.
Clang emits error message for the following code:
```
template <class F> void parallel_loop(F &&f) { f(0); }

int main() {
  int x;
  parallel_loop([&](auto y) {
    {
      x = y;
    };
  });
}
```

$ clang++ --std=gnu++14 clang_test.cc -o clang_test
clang_test.cc:9:7: error: reference to local variable 'x' declared in enclosing function 'main'
      x = y;
            ^
clang_test.cc:2:48: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<int>' requested here
            template <class F> void parallel_loop(F &&f) { f(0); }
                                                           ^
clang_test.cc:6:3: note: in instantiation of function template specialization 'parallel_loop<(lambda at clang_test.cc:6:17)>' requested here parallel_loop([&](auto y) {
           ^
clang_test.cc:5:7: note: 'x' declared here
      int x;
          ^
1 error generated.

Patch fixes this issue.

llvm-svn: 286584
2016-11-11 12:36:20 +00:00

20 lines
450 B
C++

// RUN: %clang_cc1 -std=c++14 -verify -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
// expected-no-diagnostics
template <class F> void parallel_loop(F &&f) { f(0); }
//CHECK-LABEL: @main
int main() {
// CHECK: [[X_ADDR:%.+]] = alloca i32,
int x;
// CHECK: getelementptr inbounds
// CHECK: store i32* [[X_ADDR]], i32** %
// CHECK: call
parallel_loop([&](auto y) {
#pragma clang __debug captured
{
x = y;
};
});
}