[gcc r16-5348] gccrs: fix cfg attribute error with literal predicate
Arthur Cohen
cohenarthur@gcc.gnu.org
Mon Nov 17 14:58:57 GMT 2025
https://gcc.gnu.org/g:63d2fbc4d105e4bd58394217a1a0db869fa5ff10
commit r16-5348-g63d2fbc4d105e4bd58394217a1a0db869fa5ff10
Author: Lucas Ly Ba <lucas.ly-ba@outlook.com>
Date: Thu Nov 6 16:26:12 2025 +0000
gccrs: fix cfg attribute error with literal predicate
gcc/rust/ChangeLog:
* ast/rust-ast.cc (MetaItemLitExpr::check_cfg_predicate): Make error.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4222.rs: New test.
Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
Diff:
---
gcc/rust/ast/rust-ast.cc | 3 +++
gcc/testsuite/rust/compile/issue-4222.rs | 3 +++
2 files changed, 6 insertions(+)
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 7c6a1d215af8..6d37ef7e22fb 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -3834,6 +3834,9 @@ MetaItemLitExpr::check_cfg_predicate (const Session &) const
{
/* as far as I can tell, a literal expr can never be a valid cfg body, so
* false */
+ rust_error_at (this->get_locus (), "'%s' predicate key cannot be a literal",
+ this->as_string ().c_str ());
+
return false;
}
diff --git a/gcc/testsuite/rust/compile/issue-4222.rs b/gcc/testsuite/rust/compile/issue-4222.rs
new file mode 100644
index 000000000000..b829c6f6f546
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4222.rs
@@ -0,0 +1,3 @@
+#![cfg(false)]
+// { dg-error ".false. predicate key cannot be a literal" "" { target *-*-* } .-1 }
+fn a() {}
More information about the Gcc-cvs
mailing list