[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 26 04:31:51 PDT 2023


balazske added inline comments.


================
Comment at: clang/lib/AST/ASTImporter.cpp:3936-3937
+    return std::move(Err);
+  if (ToInitializer)
+    ToField->setInClassInitializer(ToInitializer);
   return ToField;
----------------
danix800 wrote:
> Initializer could indirectly depends on this field and set the initializer while importing.
> `setInClassInitializer()` asserts that initializer should not be set more than once:
> 
> ```
>         static int ref_A();
>         static int ref_B();
>         struct A {
>           int a = ref_B();
>         };
>         struct B {
>           int b = ref_A();
>         };
>         int ref_B() { B b; return b.b; }
>         int ref_A() { A a; return a.a; }
> ```
This example code really causes problems. But import of `Expr` is not checked for recursion, the assertion in the new code fails for this test.

Why do you want to use such code? It looks to cause infinite loop when executed. Even code like `class A { int b{b}; };` is probably not correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155574



More information about the cfe-commits mailing list