[PATCH] D129573: [Clang] add a diagnostic note 'while loop outside functions' at global scope

YingChi Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 18 17:48:25 PDT 2022


inclyc added inline comments.


================
Comment at: clang/test/Parser/while-loop-outside-function.c:3
+
+while(1) {}; // expected-error {{while loop outside of function}}
+
----------------
mizvekov wrote:
> You could break this down further into more lines to test exactly where the error is placed. Id expect it to be placed at the `while` keyword.
Passes this test case, I will submit this in the next patch.

```
// RUN: %clang_cc1 -fsyntax-only -verify %s

while(1) {}; // expected-error {{while loop outside of function}}


while(1) // expected-error {{while loop outside of function}}
{

}

while(1) { // expected-error {{while loop outside of function}}

}

while(1) { // expected-error {{while loop outside of function}}

};

while(1) // expected-error {{while loop outside of function}}
{

}

while(1) { // expected-error {{while loop outside of function}}

};

// without semicolon
while(1) {} // expected-error {{while loop outside of function}}

void some_fn();

void some_fn() {
    while(1) {};
}
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129573/new/

https://reviews.llvm.org/D129573



More information about the cfe-commits mailing list