circle icon indicating copy to clipboard operation
circle copied to clipboard

Can't compile reflection/one.cxx

Open felixf4xu opened this issue 1 year ago • 1 comments

Hi,

I downloaded build 200 and tried to compile https://github.com/seanbaxter/circle/blob/master/reflection/one.cxx but I got this error:

code:

#include <cstdio>
#include <string>

struct record_t {
  std::string first;
  std::string last;
  char32_t middle_initial;
  int year_of_birth;  
};

template<typename type_t>
void print_members() {
  printf("%s:\n", @type_string(type_t));
  @meta for(int i = 0; i < @member_count(type_t); ++i) {
    printf("%d: %s - %s\n", i, @member_type_string(type_t, i), 
      @member_name(type_t, i));
  }
}

int main() {
  print_members<record_t>();
}

output:

ODR used by: int main()
one.cxx:21:26
  print_members<record_t>(); 
                         ^

  error: command line macros:2:1
  object has invalid storage duration
  
  ^

I played it a little more by deleting random code and found that if I delete @meta then the following code can compile:

  for(int i = 0; i < @member_count(type_t); ++i) {
    printf("%d: %s - %s\n", i, @member_type_string(type_t, i),
      @member_name(type_t, i));
  }

but the output is incorrect:

record_t:
0: std::string - first
1: std::string - first
2: std::string - first
3: std::string - first

felixf4xu avatar Oct 09 '23 02:10 felixf4xu

I'm not sure if it's related circle classic and new circle as mentioned at https://github.com/seanbaxter/circle/blob/master/new-circle/README.md#meta

felixf4xu avatar Oct 09 '23 02:10 felixf4xu