https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124215

            Bug ID: 124215
           Summary: [reflection] const pointer type can't find member list
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zlin174 at bloomberg dot net
  Target Milestone: ---

the exact version of GCC: GCC trunk
the system type: x86_64 Linux
the options given when GCC was configured/built: GCC trunk
the complete command line that triggers the bug: -freflection -std=c++26
the compiler output (error messages, warnings, etc.): nonstatic_data_members_of
on const pointer type is empty


In the following code snippet, no output under const type (while non-const type
has expected output):

```
#include <meta>
#include <string>
#include <iostream>

struct Test {
    int a;
    char b;

};

template <typename T>
void populate_raw_message([[maybe_unused]] T *msg)
{
    using NonConstT = std::remove_cv_t<T>;
    constexpr auto access = std::meta::access_context::current();
    std::cout << "Reflection on const type:" << std::endl;
    template for (constexpr std::meta::info member :
define_static_array(std::meta::nonstatic_data_members_of(^^T, access)))
    {
        std::cout << std::string(std::meta::identifier_of(member)) <<
std::endl; 
    }

    std::cout << "Reflection on non-const type:" << std::endl;
    template for (constexpr std::meta::info member :
define_static_array(std::meta::nonstatic_data_members_of(^^NonConstT, access)))
    {
        std::cout << std::string(std::meta::identifier_of(member)) <<
std::endl; 
    }
}

int main(){
    const Test t(10, 'a');
    populate_raw_message(&t);
}
```


Here is a compiler explorer link to show different output between Clang and
GCC:
https://godbolt.org/z/Tebn7dEvj

Reply via email to