Skip to content

Commit b8ef598

Browse files
sakupan102P-E-P
authored andcommitted
Evaluate the enum's discriminant in a const context
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc: Evaluate the enum's discriminant in a const context gcc/testsuite/ChangeLog: * rust/compile/enum_discriminant1.rs: New test. Signed-off-by: Ryutaro Okada <[email protected]>
1 parent 7651217 commit b8ef598

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

gcc/rust/backend/rust-compile-resolve-path.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ ResolvePathRef::attempt_constructor_expression_lookup (
105105

106106
// make the ctor for the union
107107
HIR::Expr &discrim_expr = variant->get_discriminant ();
108+
ctx->push_const_context ();
108109
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
110+
ctx->pop_const_context ();
109111
tree folded_discrim_expr = fold_expr (discrim_expr_node);
110112
tree qualifier = folded_discrim_expr;
111113

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum Foo {
2+
Bar = 3 + 12,
3+
}
4+
5+
fn test() -> Foo { // { dg-warning "function is never used" }
6+
return Foo::Bar;
7+
}

0 commit comments

Comments
 (0)