Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static_assert(size, str) causing an error #5872

Open
sivansh11 opened this issue Dec 15, 2024 · 3 comments
Open

static_assert(size, str) causing an error #5872

sivansh11 opened this issue Dec 15, 2024 · 3 comments
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case.

Comments

@sivansh11
Copy link

public struct node_t {
    aabb_t aabb;
    uint32_t is_leaf : 1;
    uint32_t primitive_count : 31;
    uint32_t first_primitive_index_or_first_child_index : FIRST_INDEX_BITS_SIZE;
    uint32_t children_count: 4;    // do not use
};
static_assert(sizeof(node_t) == 32, "sizeof(node_t) is not 32");

the static_assert line casues an error

error 20001: unexpected '(', expected ')'
static_assert(sizeof(node_t) == 32, "sizeof(node_t) is not 32");
                    ^

I believe this is a bug ?

on commit 5d8cf47

@csyonghe
Copy link
Collaborator

sizeof isn't a supported operator in Slang.

This is because without specifying a layout, the size of a type is not defined. A struct can have different sizes depending on where it is used/how it is laid out. For example the std140 and std430 layouts would have lead to different answers of sizeof(T).

For this reason, static assert checks like you provided is not possible today.

We can add support for things like sizeof(T, std430) to return a size under a specified layout, but this feature would need to come at a later time.

@sivansh11
Copy link
Author

We can add support for things like sizeof(T, std430) to return a size under a specified layout, but this feature would need to come at a later time.
yes please that would be nice, should I open a new issue as a feature request or will this issue do ?

@csyonghe
Copy link
Collaborator

Please open a separate issue so it is clear what to do.

@bmillsNV bmillsNV added the goal:forward looking Feature needed at a later date, not connected to a specific use case. label Dec 16, 2024
@bmillsNV bmillsNV added this to the Q1 2025 (Winter) milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case.
Projects
None yet
Development

No branches or pull requests

3 participants