WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@Pasta-coder
Copy link

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.

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: Emit error for #[repr] on functions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch from c1894f9 to 534d601 Compare January 4, 2026 08:35
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