[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.
Ding Fei via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 26 05:39:13 PDT 2023
danix800 added inline comments.
================
Comment at: clang/lib/AST/ASTImporter.cpp:3936-3937
+ return std::move(Err);
+ if (ToInitializer)
+ ToField->setInClassInitializer(ToInitializer);
return ToField;
----------------
balazske wrote:
> 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.
Like `int a{a};` this testcase is minimized to just show what might cause the problem.
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