Issue 60951
Summary Crash while trying to use offsetof in template lambda.
Labels new issue
Assignees
Reporter ONEMK
    This code crashes compiler when using clang 15.0.0 but compiles fine under newest versions od gcc and msvc

```cpp
#include <cstdio>
#include <cstddef>

struct Test
{
    int               a  = 1;
    inline static int sa = 2;
};

template< typename T , typename C , typename L >
consteval size_t GetOffsetOf( T C::* ptr , const L& of ){
    C* pClass = nullptr;
    return of(pClass);
}

template< typename T , typename L >
consteval const void* GetOffsetOf( const T* ptr , L ){
 return ptr;
}

#define GET_OFFSET_OF( Type , Member ) GetOffsetOf( &Type::Member  , []<typename T>( T* )->size_t{ return offsetof( T , Member ); } );

int main()
{
    constexpr auto V1 = GET_OFFSET_OF( Test, a );
    constexpr auto V2 = GET_OFFSET_OF( Test, sa );
    printf( "addr: %lld | %lld\n" , (long long)V1 , (long long)V2 );
    return 0;
}
```
Link to compiler explorer:
https://godbolt.org/z/d3dGadf78
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to