[clang] [clang][AST] fix ast-print of `extern <lang>` with >=2 declarators (PR #93131)

Artem Yurchenko via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 09:19:47 PDT 2024


================
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+// CHECK: extern "C" int printf(const char *, ...);
+extern "C" int printf(const char *...);
+
+// CHECK: extern "C++" {
+// CHECK-NEXT:   int f(int);
+// CHECK-NEXT:   int g(int);
+// CHECK-NEXT: }
+extern "C++" int f(int), g(int);
+
+// CHECK: extern "C" {
+// CHECK-NEXT:  void foo();
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  int y;
+// CHECK-NEXT: }
+extern "C" {
+  void foo(void);
+  int x, y;
----------------
temyurchenko wrote:

If you mean the splitting of `int x, y` into `int x; int y`, that's actually the «default». The declarators are split into different declarations whenever it's possible. So, the splitting doesn't happen only when there is a definition of a tagged type within the declaration, I believe. So, for example:

`union {} a, b;` → `union {\n} a, b;`

but

`int a, b;` → `int a; int b;`


That fact, that this very splitting already occurs in DeclPrinter and leads to the deviation from the original source, was the reason why I felt more comfortable to go forward with adding braces.

https://github.com/llvm/llvm-project/pull/93131


More information about the cfe-commits mailing list