Skip to content

Errors in transforming struct T {} var #588

@Ukilele

Description

@Ukilele

Hey Andreas, I am sorry that I report so many issues recently, but cppinsights is just a great tool for learning C++ and it seems I occasionally tend to dig into the slightly more odd edge cases of the language 😸

Here is the source code:

struct A {
  void f() {}
} a_var_1;

struct B {
} b_var_1, b_var_2, b_var_3;

struct {
} anonym_var_1, anonym_var_2, anonym_var_3;

struct {
} anonym_var_assign = {};

struct {
} anonym_var_array[3];

struct {
} anonym_var_dummy, *anonym_var_ptr;

And this is what cppinsights (version 26c63ad) produces:

struct A a_var_1;


struct B b_var_3;


struct __anon_8_1
{
  // inline constexpr __anon_8_1() noexcept = default;
};

__anon_8_1 anonym_var_1;
, anonym_var_2__anon_8_1 anonym_var_2;
, anonym_var_3;__anon_8_1 anonym_var_3;


struct __anon_11_1
{
};

 = {};__anon_11_1 anonym_var_assign = {};


__anon_14_1 anonym_var_array[3];


__anon_17_1 * anonym_var_ptr;

I think there are several issues, but I assume they are related. So I hope it's fine that I create just one issue.

  • 1. Creating a type and variable via struct A{} a_var_1; produces struct A a_var_1;. But instead it should show the whole type definition and a variable definition afterwards:
struct A {
  //...
};
A a_var_1;
  • 2. Creating a type and multiple variables via struct B {} b_var_1, b_var_2, b_var_3; produces struct B b_var_3; (similar like in bullet point 1.). The additional issue is, that cppinsights completely swallows the definitions of b_var_1 and b_var_2.
  • 3. Creating an anonymous type and multiple variables via struct {} anonym_var_1, anonym_var_2, anonym_var_3; does not swallow the first and second variables (other than in bullet point 2.), but only the definition of anonym_var_1 looks reasonable. The definitions of anonym_var_2 and anonym_var_3 look wrong.
  • 4. Creating an anonymous type and one variable which gets initialized like in struct {} anonym_var_assign = {}; looks wrong in a sense that the initialization part ( = {};) appears both before and after the variable anonym_var_assign.
  • 5. Creating an anonymous type and one or multiple variables with additional declarators (like array ([3]) or pointer (*)) leads to the effect that both the anonymous struct definition does not get generated by cppinsights and that previous variable definitions (anonym_var_dummy) get swallowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions