mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 04:06:46 +00:00

Unlike other *Loc member in FunctionScopeInfo, we didn't clear FirstVLALoc in 'FunctionScopeInfo::Clear()'. Then it will be problematic for the following case: ``` void bar(int n) { int array[n]; return; } coroutine foo(int n) { co_return; } ``` When we parse `foo`, the FirstVLALoc is still valid, then the compiler will report `vla in coroutine` error in bar, which is super odd. After this patch, we can fix this.
36 lines
831 B
C++
36 lines
831 B
C++
// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -Wno-vla-cxx-extension -verify
|
|
#include "Inputs/std-coroutine.h"
|
|
|
|
struct promise;
|
|
|
|
struct coroutine : std::coroutine_handle<promise> {
|
|
using promise_type = ::promise;
|
|
};
|
|
|
|
struct promise
|
|
{
|
|
coroutine get_return_object();
|
|
std::suspend_always initial_suspend() noexcept;
|
|
std::suspend_always final_suspend() noexcept;
|
|
void return_void();
|
|
void unhandled_exception();
|
|
};
|
|
|
|
// Test that we won't report the error incorrectly.
|
|
void bar(int n) {
|
|
int array[n];
|
|
return;
|
|
}
|
|
|
|
coroutine foo(int n) {
|
|
int array[n]; // expected-error {{variable length arrays in a coroutine are not supported}}
|
|
co_return;
|
|
}
|
|
|
|
void lambda() {
|
|
[](int n) -> coroutine {
|
|
int array[n]; // expected-error {{variable length arrays in a coroutine are not supported}}
|
|
co_return;
|
|
}(10);
|
|
}
|