Skip to content

Conversation

@Pasta-coder
Copy link
Contributor

The #[repr] attribute is only valid for structs, enums, and unions. Applying it to a function is invalid and should result in an error. This patch adds a check in the attribute visitor to reject #[repr] on functions, matching rustc behavior.

Fixes #4232

gcc/rust/ChangeLog:

* util/rust-attributes.cc: Emit error for #[repr] on functions.

gcc/testsuite/ChangeLog:

* rust/compile/repr_on_function.rs: New test.

@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch from c1894f9 to 534d601 Compare January 4, 2026 08:35
@Pasta-coder Pasta-coder marked this pull request as draft January 6, 2026 13:26
@Pasta-coder
Copy link
Contributor Author

drafted to resolve conflicts

@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch from 2128917 to 98a508e Compare January 7, 2026 19:43
The #[repr] attribute is only valid for structs, enums, and unions.
Applying it to a function is invalid and should result in an error.
This patch adds a check in the attribute visitor to reject #[repr]
on functions, matching rustc behavior.

Fixes Rust-GCC#4232

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (AttributeChecker::check_attributes): Emit error for #[repr].

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4232.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch from 98a508e to 3c307f9 Compare January 7, 2026 19:58
@Pasta-coder Pasta-coder marked this pull request as ready for review January 7, 2026 21:08
@Pasta-coder
Copy link
Contributor Author

@P-E-P please review .

thankyou .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repr attribute should give error when applied to other than struct enum or union

1 participant