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 <0001jayant@gmail.com>
{
check_link_section_attribute (attribute);
}
+ else if (result.name == Attrs::REPR)
+ {
+ rust_error_at (
+ attribute.get_locus (),
+ "attribute should be applied to a struct, enum, or union");
+ }
}
if (fun.has_body ())
--- /dev/null
+// { dg-options "-w" }
+#[repr(C)] // { dg-error "attribute should be applied to a struct, enum, or union" }
+fn a() {}
\ No newline at end of file