id_aa stringlengths 5 8 | title stringlengths 16 50 | category stringclasses 7
values | prompt stringlengths 63 759 | system_prompt stringlengths 25 111 | rubric stringlengths 129 785 | expected_deliverables stringclasses 1
value | reference_files stringclasses 1
value |
|---|---|---|---|---|---|---|---|
rust_001 | GAT higher-ranked implied static | Rust | Assume stable Rust 1.85.0, edition 2021. Does the following program compile? Give the decisive lifetime diagnosis, including what the higher-ranked bound implies for `data`.
```rust
use std::fmt::Debug;
trait L { type Item<'a> where Self:'a; fn next<'a>(&'a mut self)->Option<Self::Item<'a>>; }
struct W<'x>{ s:&'x mut [... | You are a Rust language-semantics expert. Answer only under the stated toolchain and explain the decisive rule. | compilation_conclusion: Correct compilation result under Rust 1.85.0.
0 — Says the program compiles, or gives no definite conclusion.
1 — Says it fails to compile because the higher-ranked associated-type bound effectively requires the borrow backing `W` to be valid for `'static` under the current borrow checker's ... | ||
rust_002 | Underscore pattern and drop timing | Rust | Assume stable Rust 1.85.0, edition 2021. What exact text is printed?
```rust
struct P(&'static str);
impl Drop for P { fn drop(&mut self){ print!("{}",self.0); } }
fn main(){
let x=P("x");
let y=P("y");
let _=x;
print!("A");
drop(y);
print!("B");
}
```
Explain whether `let _ = x` moves or drops `x`, and when each... | You are a Rust language-semantics expert. Give the exact output and decisive reasoning. | exact_output: The exact character sequence.
0 — Gives any output other than `AyBx`.
1 — Gives exactly `AyBx`.
drop_semantics: Correctly accounts for the wildcard pattern and scopes.
0 — Claims `let _ = x` moves or immediately drops `x`, or otherwise gives destructor timing inconsistent with the output.
1 — Sta... | ||
rust_003 | Autoref method resolution to double reference | Rust | Assume stable Rust 1.85.0. Does this compile? If so, explain the receiver adjustment that makes the implementation applicable.
```rust
trait T { fn f(self); }
impl T for &&i32 { fn f(self) {} }
fn main(){ let x=0; (&x).f(); }
``` | Apply Rust method-call receiver candidate construction precisely. | resolution_result: Compilation result and selected implementation.
0 — Says no method applies to receiver `&i32`.
1 — States that the program compiles and selects the `T for &&i32` implementation.
candidate_reasoning: Required implicit receiver adjustment.
0 — Claims the compiler dereferences `&x` to `i32` and c... | ||
rust_004 | Move closure capture and outer copy | Rust | Assume stable Rust 1.85.0. What exact text is printed, and why is the closure callable twice?
```rust
fn main(){
let mut n=0;
let mut c=move || { n+=1; print!("{n}"); };
c(); c();
print!("-{n}");
}
``` | Give exact output and closure-trait/capture reasoning. | exact_output: Exact standard output.
0 — Gives anything other than `12-0`.
1 — Gives exactly `12-0`.
capture_and_trait: Explains the independent captured state.
0 — Claims the outer `n` becomes 2, or that the closure is `FnOnce` merely because it is `move`.
1 — Explains that `i32` is copied into the move closu... | ||
rust_005 | Two-phase borrow in method arguments | Rust | Assume stable Rust 1.85.0. Is this program accepted? Explain the interaction between two-phase borrowing and argument evaluation.
```rust
fn main(){
let mut v=vec![10,20];
v.push(v.len());
println!("{v:?}");
}
``` | Answer under stable Rust and distinguish reservation from activation. | result: Compilation and output.
0 — Says borrow checking rejects it or gives output other than `[10, 20, 2]`.
1 — States that it compiles and prints `[10, 20, 2]`.
two_phase_reasoning: Explains why the immutable length read is permitted.
0 — Says mutable and immutable borrows freely overlap in general or omits t... | ||
rust_006 | Overlapping conditional blanket impls | Rust | Assume stable Rust 1.85.0. Does this compile? Give the precise coherence reason.
```rust
trait X {}
impl<T> X for T where T: Iterator {}
impl<T> X for T where T: IntoIterator {}
fn main(){}
``` | Analyze Rust coherence, including possible types rather than currently named standard types. | coherence_result: Whether the impl set is accepted.
0 — Says it compiles because `Iterator` and `IntoIterator` are different traits.
1 — States that the two blanket implementations conflict and the crate is rejected.
overlap_reasoning: Explains existential overlap.
0 — Bases the answer only on whether a particul... | ||
rust_007 | ManuallyDrop inside array | Rust | Assume stable Rust 1.85.0. What exact output is guaranteed?
```rust
use std::mem::ManuallyDrop;
struct D(u8);
impl Drop for D { fn drop(&mut self){print!("{}",self.0)} }
fn main(){
let mut a=[ManuallyDrop::new(D(1)),ManuallyDrop::new(D(2))];
unsafe { ManuallyDrop::drop(&mut a[0]); }
print!("X");
}
```
Account for ev... | Give exact output and distinguish dropping the wrapper from its payload. | exact_output: Exact destructor and print sequence.
0 — Gives anything other than `1X`.
1 — Gives exactly `1X`.
destructor_accounting: Why the second payload is not dropped.
0 — Claims array scope exit automatically drops `D(2)` or double-drops `D(1)`.
1 — Explains that the explicit unsafe call drops only the f... | ||
rust_008 | Invalid bool representation | Rust | Assume stable Rust 1.85.0. Is the marked unsafe read defined under Rust's validity requirements?
```rust
fn main(){
let b: bool = unsafe { std::mem::transmute::<u8,bool>(2) };
println!("{b}"); // marked use
}
```
Do not predict a particular optimized output; classify the program and identify the violated invariant. | Classify unsafe-code validity precisely; do not treat observed output as specification. | validity_classification: Correct semantic classification.
0 — Calls it defined, implementation-defined, or merely unspecified.
1 — Classifies constructing/using the invalid `bool` value as undefined behavior; no output is guaranteed.
invariant: Names the invalid representation.
0 — Claims every nonzero byte is a... | ||
rust_009 | Supertrait method disambiguation | Rust | Assume stable Rust 1.85.0. What exact output does this produce?
```rust
trait A { fn f(&self){print!("A")} }
trait B: A { fn f(&self){print!("B")} }
struct S;
impl A for S {}
impl B for S {}
fn main(){
let x:&dyn B=&S;
B::f(x);
A::f(x);
}
``` | Apply trait-object coercion and fully qualified trait calls. | exact_output: Exact text or compilation diagnosis.
0 — Says it fails or gives output other than `BA`.
1 — States that it compiles and prints exactly `BA`.
dispatch_reasoning: Explains the two explicitly selected defaults.
0 — Treats the same-named supertrait method as an override or says `B::f` dynamically repla... | ||
rust_010 | Sized generic method on trait object | Rust | Assume stable Rust 1.85.0. Does this compile? Explain object safety/dyn compatibility at the coercion.
```rust
trait Q {
fn make<T>(&self, x:T) where Self:Sized;
fn n(&self)->i32 {3}
}
struct S;
impl Q for S { fn make<T>(&self,_:T){} }
fn main(){ let q:&dyn Q=&S; println!("{}",q.n()); }
``` | Analyze dyn compatibility method by method. | compilation_and_output: Correct result.
0 — Says the generic method makes the trait non-dyn-compatible, or gives output other than `3`.
1 — States that it compiles and prints `3`.
dyn_reasoning: Effect of the `Self: Sized` restriction.
0 — Claims generic methods are always callable through trait objects.
1 — E... | ||
go_001 | Select operand evaluation | Go | Assume Go 1.23. What exact text is printed? Explain expression evaluation on entry to `select` and why the selected case wins.
```go
package main
import "fmt"
func ch(s string,c chan int) chan int { fmt.Print(s); return c }
func val(s string) int { fmt.Print(s); return 7 }
func main(){
var nilc chan int; c:=make(chan ... | Apply the Go 1.23 specification and give exact output. | exact_output: Exact emitted text.
0 — Gives anything other than `AaBY0`.
1 — Gives exactly `AaBY0`.
select_reasoning: Evaluation and selection rules.
0 — Says only the chosen case operands are evaluated, or that default runs.
1 — Explains that channel operands and send RHS expressions for all cases are evaluat... | ||
go_002 | Typed nil inside interface | Go | Assume Go 1.23. Does this program panic, and what exact line is printed before termination?
```go
package main
import "fmt"
type E struct{}
func (*E) Error() string { return "e" }
func f() error { var p *E=nil; return p }
func main(){ e:=f(); fmt.Printf("%t %T\n",e==nil,e); fmt.Println(e.Error()) }
``` | Distinguish a nil interface from an interface containing a typed nil pointer. | observable_result: Printed line and panic status.
0 — Says `e == nil`, gives a different first line, or says no panic occurs.
1 — States the first line is `false *main.E`, then the call panics due to dereferencing the nil `*E` receiver while evaluating `return "e"`?
2 — States the first line is `false *main.E` a... | ||
go_003 | Range slice header snapshot | Go | Assume Go 1.23. What exact text is printed?
```go
package main
import "fmt"
func main(){
s:=[]int{1,2,3}
for i,v:=range s {
fmt.Print(i,v,";")
if i==0 { s=append(s,4,5); s[1]=9 }
}
fmt.Print("|",s)
}
```
Explain which length and backing values the range loop observes. | Give exact output under the language specification. | exact_output: Exact output including separators.
0 — Gives anything other than `01;12;23;|[1 9 3 4 5]`.
1 — Gives exactly `01;12;23;|[1 9 3 4 5]`.
range_reasoning: Why the mutation is not seen by loop values.
0 — Claims the loop grows to five iterations or must print 9 for index 1.
1 — Explains that the range ... | ||
go_004 | Generic operator over type set | Go | Assume Go 1.23. Does this generic function compile? Give the precise reason.
```go
package p
type N interface{ ~int | ~string }
func F[T N](a,b T) T { return a+b }
``` | Apply operator validity across every type in the constraint's type set. | compilation: Whether `+` is permitted for all types in the type set.
0 — Says it is rejected because int addition and string concatenation are different operations.
1 — States that it compiles.
type_set_reasoning: Common operation and result type.
0 — Claims a type switch or conversion is required.
1 — Explain... | ||
go_005 | Named result, return, and defer arguments | Go | Assume Go 1.23. What exact text is printed?
```go
package main
import "fmt"
func f() (r int) {
defer func(x int){ fmt.Print(x,r); r++ }(r)
r=5
return 7
}
func main(){fmt.Print("|",f())}
``` | Track defer argument evaluation and named-result assignment exactly. | exact_output: Exact output order.
0 — Gives anything other than `07|8`.
1 — Gives exactly `07|8`.
defer_reasoning: Distinguishes argument capture from closure access.
0 — Says deferred argument `x` is evaluated at function return or misses the final increment.
1 — Explains that `x` captures initial `r=0` when ... | ||
go_006 | Close-receive happens-before | Go | Assume Go 1.23. Is the final value of `x` guaranteed to be 1, guaranteed to be 2, or not constrained to either? Explain using channel close synchronization.
```go
package main
var x int
func main(){
c:=make(chan struct{})
go func(){ x=1; close(c) }()
<-c
x=2
println(x)
}
``` | Use the Go memory model, not scheduling intuition. | value: Guaranteed printed integer.
0 — Says 1, unconstrained, or race-dependent.
1 — States it is guaranteed to print 2.
memory_order: Happens-before chain and race status.
0 — Claims the read/write of `x` race or that close provides no synchronization.
1 — Explains that closing `c` is synchronized before the ... | ||
go_007 | Map elements and method sets | Go | Assume Go 1.23. What exact text is printed?
```go
package main
import "fmt"
type I interface{ M() }
type S struct{ n int }
func (s S) M(){fmt.Print("V",s.n)}
func (s *S) P(){fmt.Print("P",s.n)}
func main(){
m:=map[int]S{0:{3}}
m[0].M()
var i I=m[0]; i.M()
}
``` | Analyze addressability and value-receiver method sets. | result: Compilation and output.
0 — Says map elements cannot be used for any method call, or gives output other than `V3V3`.
1 — States that it compiles and prints `V3V3`.
method_set_reasoning: Why `M` works despite non-addressability.
0 — Relies on implicit addressing of `m[0]`.
1 — Explains that `S` itself h... | ||
go_008 | Buffered send synchronization | Go | Assume Go 1.23 and that `GOMAXPROCS` may be any positive value. Is this program data-race-free? Is it guaranteed to print `1`?
```go
package main
var x int
func main(){
done:=make(chan bool,1)
go func(){ x=1; done<-true }()
<-done
println(x)
}
``` | Use the formal channel synchronization rule. | conclusion: Race freedom and value.
0 — Calls it racy or says the print may be 0.
1 — States that it is data-race-free and guaranteed to print 1.
happens_before: Correct synchronization edge for the buffered channel.
0 — Claims buffered sends never synchronize until the buffer is reused.
1 — Explains that a se... | ||
go_009 | Overlapping append within slice | Go | Assume Go 1.23. What exact text is printed?
```go
package main
import "fmt"
func main(){
a:=[]int{1,2,3}
b:=append(a[:1],a[2:]...)
fmt.Print(a,"|",b)
}
```
Account for overlapping source and destination and the shared backing array. | Apply append's overlap behavior and capacity rules. | exact_output: Exact slice values.
0 — Gives anything other than `[1 3 3]|[1 3]`.
1 — Gives exactly `[1 3 3]|[1 3]`.
backing_array_reasoning: Why mutation occurs in place.
0 — Claims overlap is undefined or that allocation is required.
1 — Explains that `a[:1]` has sufficient capacity, append may reuse the same... | ||
go_010 | Constraint-only comparable interface | Go | Assume Go 1.23. Does this declaration compile? Explain why `comparable` does or does not satisfy the ordinary interface use.
```go
package p
var x interface{ comparable }
``` | Distinguish basic interfaces from constraint-only non-basic interfaces. | compilation: Use outside a type constraint.
0 — Says it declares an interface value accepting all comparable dynamic values.
1 — States that it does not compile because `interface{ comparable }` may only be used as a type constraint, not as the type of an ordinary variable.
interface_reasoning: Nature of the inter... | ||
c_001 | C17 release sequence through relaxed RMW | C | Assume ISO C17. `data` and `flag` are initialized to zero before three threads begin. B's successful compare-exchange reads A's `1`, and C's terminating acquire load reads B's `2`.
```c
#include <stdatomic.h>
atomic_int data,flag;
void A(void){atomic_store_explicit(&data,1,memory_order_relaxed);atomic_store_explicit(&f... | Give a formal C17 memory-model argument. | two_conclusions: Correct result for RMW and store variants.
0 — Gets both variants wrong or gives no distinction.
1 — Correctly says the RMW variant forbids 0, but does not correctly classify the store variant.
2 — Says the RMW variant cannot return 0; with B's relaxed store, 1 is not guaranteed and C may return ... | ||
c_002 | Object representation copied twice | C | Assume ISO C17 and a conforming hosted implementation where `unsigned char` has no padding bits. Is this function defined for every `float x`? If defined, what semantic property does it test?
```c
#include <string.h>
int f(float x){ unsigned char a[sizeof x],b[sizeof x]; memcpy(a,&x,sizeof x); memcpy(b,&x,sizeof x); re... | Separate value semantics, padding, and indeterminate representations. | classification: Whether the operations are defined.
0 — Calls it undefined merely because `float` may contain padding or NaNs.
1 — States it is defined and always returns 1 for the two copies taken from the same unchanged object.
representation_reasoning: What `memcpy` and `memcmp` compare.
0 — Claims it compare... | ||
c_003 | Effective type versus common initial sequence | C | Assume ISO C17. Classify the marked access.
```c
#include <stdlib.h>
struct A{int x;}; struct B{int x;};
int main(void){
void *p=malloc(sizeof(struct A));
((struct A*)p)->x=42;
int y=((struct B*)p)->x; /* marked */
free(p); return y;
}
```
Is common initial sequence relevant? | Apply C17 effective-type and union common-initial-sequence rules. | classification: Definedness of the lvalue access.
0 — Calls the read defined because both structs begin with `int x`.
1 — Classifies the read through `struct B *` as undefined behavior.
alias_reasoning: Effective type and inapplicable exception.
0 — Invokes the common-initial-sequence permission outside a union.... | ||
c_004 | Unsequenced scalar modifications | C | Assume ISO C17. Is the result of `f(5)` defined, unspecified, implementation-defined, or undefined?
```c
int f(int i){ return i++ + i++; }
```
Do not give a numeric result unless the standard guarantees one. | Use C17 sequencing terminology precisely. | classification: Correct standard category.
0 — Calls the result 11, 12, unspecified, or implementation-defined.
1 — Classifies the expression as undefined behavior.
sequencing_reason: The conflicting evaluations.
0 — Attributes it merely to unspecified operand evaluation order.
1 — States that the two side eff... | ||
c_005 | Unsequenced pointer increments | C | Assume ISO C17. What does `g()` return?
```c
int g(void){
int a[3]={10,20,30};
int *p=&a[0];
return *p++ + *p++;
}
```
Classify the expression before attempting arithmetic. | Do not infer an execution order where the standard supplies none. | classification: Whether a return value is defined.
0 — Gives 30, 40, or any fixed value.
1 — States that behavior is undefined, so no return value is guaranteed.
reason: Why distinct pointees do not save it.
0 — Says it is safe because the dereferences can refer to different array elements.
1 — Explains that b... | ||
c_006 | Byte buffer cast to uint32_t | C | Assume ISO C17, `CHAR_BIT==8`, and `uint32_t` exists. Is `h` strictly defined on every implementation satisfying those assumptions?
```c
#include <stdint.h>
uint32_t h(unsigned char *p){ return *(uint32_t*)p; }
```
The caller guarantees only that `p` points to the first element of an array of four `unsigned char` objec... | Account separately for alignment and effective type. | classification: Portability and UB.
0 — Calls it strictly defined because character arrays may alias any type.
1 — States it is not strictly defined and may have undefined behavior.
two_hazards: Required independent reasons.
0 — Mentions only endianness or value differences.
1 — Identifies at least one of insu... | ||
c_007 | String literal exactly fills character array | C | Assume ISO C17. Is this initializer a constraint violation, and if accepted what is `sizeof s`?
```c
char s[3] = "abc";
``` | Distinguish ordinary string storage from the character-array initialization exception. | answer: Validity and size.
0 — Says it is invalid because no null terminator fits, or gives a size other than 3.
1 — States it is valid and `sizeof s` is 3.
initialization_rule: Terminator omission exception.
0 — Claims the array nevertheless contains four bytes or an implicit terminator out of bounds.
1 — Exp... | ||
c_008 | One-past pointer equality across objects | C | Assume ISO C17. Is `p == q` guaranteed true, guaranteed false, or unspecified after these declarations?
```c
int a[1], b[1];
int *p = a + 1;
int *q = b;
```
Assume the implementation may place the arrays adjacently. | Apply pointer equality rules, not relational comparison rules. | classification: Allowed equality result.
0 — Says it is guaranteed false solely because the pointers derive from different arrays, or guaranteed true.
1 — States that the comparison can be true if the one-past address of `a` equals the address of `b`, and otherwise false; placement is implementation-dependent, so t... | ||
c_009 | Dereferencing malloc zero result | C | Assume ISO C17. Does this function have defined behavior for `n==0`?
```c
#include <stdlib.h>
void f(size_t n){ int *p=malloc(n*sizeof *p); if(!p) return; p[0]=1; free(p); }
```
Account for every permitted result of `malloc(0)`. | Quantify over all conforming `malloc(0)` behaviors. | classification: Definedness at zero size.
0 — Calls it always safe because the null check succeeds or returns.
1 — States that it is not guaranteed defined: `malloc(0)` may return a non-null pointer that cannot be used to access an object, and `p[0]=1` then has undefined behavior.
malloc_zero_cases: Both allowed o... | ||
c_010 | Flexible array member sizeof | C | Assume ISO C17 and `sizeof(int)==4`. What is the value of `sizeof(struct S)`?
```c
struct S { char c; int a[]; };
```
Is 8 the only conforming answer? Explain the flexible-array sizing rule and trailing padding. | Do not assume a particular ABI beyond the stated integer size. | portability_conclusion: Whether one numeric size follows.
0 — States that the standard guarantees 8.
1 — States that the standard does not determine a unique numeric size from `sizeof(int)==4`; 8 is possible but not the only conforming answer.
layout_reasoning: Rule for flexible member omission and padding.
0 — ... | ||
cpp_001 | Replacing a base subobject in place | C++ | Assume ISO C++20. Is the marked call defined?
```cpp
#include <new>
struct B{virtual ~B()=default;virtual int f()const{return 1;}};
struct D:B{int f()const override{return 2;}};
void replace(B* p){p->~B();::new((void*)p) B; int n=p->f(); /* marked */}
int main(){alignas(D) unsigned char s[sizeof(D)];D*d=::new((void*)s)... | Apply ISO C++20 lifetime and transparent-replaceability rules. | classification: Definedness of the marked use.
0 — Calls the use defined because the address is unchanged.
1 — States that using `p` directly for the call is not valid via transparent replacement when the old object was a base-class subobject.
minimal_fix: Correct local placement-new target.
0 — Suggests only ca... | ||
cpp_002 | List initialization constructor priority | C++ | Assume ISO C++20. What exact text is printed?
```cpp
#include <iostream>
struct X{X(){std::cout<<"D";} X(int){std::cout<<"I";} X(std::initializer_list<int>){std::cout<<"L";}};
int main(){X a; X b{}; X c{1}; X d(1);}
``` | Give exact output using C++20 initialization rules. | exact_output: Constructor sequence.
0 — Gives anything other than `DDLI`.
1 — Gives exactly `DDLI`.
initialization_reasoning: Constructor selected for each declaration.
0 — Claims empty braces prefer the initializer-list constructor.
1 — Explains that default- and empty-list-initialization select the default c... | ||
cpp_003 | Auto forwarding-reference deduction | C++ | Assume ISO C++20. Does this declaration compile, and what type is deduced for `x`?
```cpp
const int a=1;
auto&& x=a;
``` | State the exact deduced declared type including cv/ref qualifiers. | deduced_type: Exact type.
0 — Gives `int&&`, `const int&&`, or `int&`.
1 — States that it compiles and `x` has type `const int&`.
deduction_reason: Reference collapsing and lvalue deduction.
0 — Treats `auto&&` as always an rvalue reference.
1 — Explains that because the initializer is an lvalue, `auto` deduce... | ||
cpp_004 | Discarded constexpr-if statement | C++ | Assume ISO C++20. Is the program well-formed?
```cpp
template<class T> void f(T){static_assert(sizeof(T)==0);}
int main(){ if constexpr(false) f(0); }
```
Explain whether the function template specialization is instantiated. | Apply template instantiation rules to a non-template enclosing function. | well_formedness: Compilation result.
0 — Says `f<int>` is instantiated and the assertion fails.
1 — States that the program is well-formed.
instantiation_reasoning: Effect of the discarded statement.
0 — Claims discarded statements are not parsed or need not be syntactically valid.
1 — Explains that the false ... | ||
cpp_005 | Virtual dispatch with static default argument | C++ | Assume ISO C++20. What exact text is printed?
```cpp
#include <iostream>
struct A{virtual void f(int x=1){std::cout<<"A"<<x;}};
struct B:A{void f(int x=2)override{std::cout<<"B"<<x;}};
int main(){B b; A* p=&b; p->f();}
``` | Separate virtual function selection from default-argument binding. | exact_output: Exact output.
0 — Gives anything other than `B1`.
1 — Gives exactly `B1`.
dispatch_reason: Two different static/dynamic decisions.
0 — Uses B's default 2 because B's override runs.
1 — Explains that virtual dispatch selects `B::f`, while default arguments are bound from the static type of the cal... | ||
cpp_006 | Exception unwinding destructor order | C++ | Assume ISO C++20. What exact text is printed?
```cpp
#include <iostream>
struct X{~X(){std::cout<<"X";}};
int main(){try{X x; throw 1;}catch(int){std::cout<<"C";}std::cout<<"E";}
``` | Give exact observable order. | exact_output: Destructor, handler, continuation sequence.
0 — Gives anything other than `XCE`.
1 — Gives exactly `XCE`.
unwinding_reason: Why destruction precedes handler body.
0 — Places destruction after the catch or at end of main.
1 — Explains that stack unwinding destroys automatic `x` before control ente... | ||
cpp_007 | Transparent replacement with const member | C++ | Assume ISO C++20. Is `p` usable after the placement new without laundering?
```cpp
#include <new>
struct X{const int n;};
int main(){X x{1}; X* p=&x; x.~X(); ::new((void*)&x) X{2}; return p->n;}
```
If not, state the required expression and resulting return value. | Apply C++20 transparent replacement; do not apply obsolete pre-C++20 folklore. | answer: Pointer usability and returned value.
0 — Says `std::launder(p)` is required solely because `X` has a const data member.
1 — States that in C++20 the complete object is transparently replaced, `p` automatically denotes the new `X`, and the program returns 2 without laundering.
lifetime_reason: Applicabilit... | ||
cpp_008 | Inactive union member read | C++ | Assume ISO C++20. Is the read defined?
```cpp
union U{int i; float f;};
int main(){U u;u.i=0;return u.f==0.0f;}
``` | Classify under ISO C++20, independent of compiler extensions. | classification: Definedness of reading `u.f`.
0 — Calls it a defined bit reinterpretation yielding floating zero.
1 — States that reading the inactive `float` member is undefined behavior under ISO C++20.
union_reason: Active member and exceptions.
0 — Invokes C-style type punning as a general C++ permission.
... | ||
cpp_009 | Named forwarding reference value category | C++ | Assume ISO C++20. Which overload is called?
```cpp
#include <iostream>
void f(int&){std::cout<<"L";} void f(const int&){std::cout<<"C";} void f(int&&){std::cout<<"R";}
template<class T> void g(T&& x){f(x);f(static_cast<T&&>(x));}
int main(){g(1);}
``` | Give exact output and deduction/value-category reasoning. | exact_output: Overload sequence.
0 — Gives anything other than `LR`.
1 — Gives exactly `LR`.
forwarding_reason: Named variable and cast categories.
0 — Treats named `x` as an xvalue merely because its type is `int&&`.
1 — Explains that `T` is `int`; named expression `x` is an lvalue and calls `f(int&)`, while ... | ||
cpp_010 | Explicit constructor in braced argument | C++ | Assume ISO C++20. Does this compile?
```cpp
struct X{explicit X(int){}};
void f(X){}
int main(){f({1});}
```
Distinguish direct-list-initialization from copy-list-initialization of a parameter. | Apply copy-list-initialization rules precisely. | compilation: Whether the call is well-formed.
0 — Says braces directly initialize `X` and therefore allow the explicit constructor.
1 — States that the call is ill-formed.
initialization_reason: Why explicit is disallowed.
0 — Attributes rejection to narrowing or missing conversion.
1 — Explains that the brace... | ||
zig_001 | Slice aliases array storage | Zig | Assume Zig 0.13.0 in Debug mode. What exact text is printed?
```zig
const std=@import("std");
pub fn main() !void {
var a:[3]u8=.{1,2,3};
const s=a[0..];
a[1]=9;
std.debug.print("{d}-{d}\n",.{s[1],s.len});
}
``` | Answer for Zig 0.13.0 exactly. | exact_output: Exact printed line.
0 — Gives anything other than `9-3`.
1 — Gives exactly `9-3`.
alias_reason: Slice representation and mutation.
0 — Claims slicing copies the array.
1 — Explains that `s` is a slice referencing `a`'s storage with length 3, so the later write to `a[1]` is observed through `s[1]`... | ||
zig_002 | Runtime value passed to comptime parameter | Zig | Assume Zig 0.13.0. Does this compile?
```zig
const std=@import("std");
fn f(comptime n:usize) usize { return n+1; }
pub fn main() void { var x:usize=3; std.debug.print("{}",.{f(x)}); }
```
Explain the stage mismatch, if any. | Distinguish compile-time-known from runtime values in Zig 0.13.0. | compilation: Whether the call is legal.
0 — Says the compiler evaluates `f` at runtime.
1 — States that it fails to compile because `x` is runtime-known and cannot satisfy a `comptime` parameter.
stage_reason: What `comptime` requires.
0 — Claims `var` values are always compile-time-known when initialized by lit... | ||
zig_003 | defer and errdefer ordering | Zig | Assume Zig 0.13.0. What exact text is printed?
```zig
const std=@import("std");
fn f() !u8 { errdefer std.debug.print("E",.{}); defer std.debug.print("D",.{}); return error.Bad; }
pub fn main() void { _=f() catch |e| {std.debug.print("C:{s}",.{@errorName(e)}); return;}; }
``` | Track scope exit and error return order. | exact_output: Exact text.
0 — Gives anything other than `DEC:Bad`.
1 — Gives exactly `DEC:Bad`.
cleanup_reason: LIFO cleanup and catch.
0 — Places the catch before cleanup or omits one cleanup.
1 — Explains that returning an error runs both deferred actions in reverse registration order: ordinary `defer` print... | ||
zig_004 | Checked versus wrapping integer addition | Zig | Assume Zig 0.13.0 in Debug mode. What happens?
```zig
const std=@import("std");
pub fn main() void { var x:u8=255; x+=1; std.debug.print("{}",.{x}); }
```
Then state how the behavior differs if `x +%= 1` replaces `x += 1`. | Answer by build-mode arithmetic semantics. | two_results: Checked and wrapping forms.
0 — Says both forms wrap to zero.
1 — States that `+=` overflows and traps/panics in Debug mode, while `+%=` performs wrapping addition and prints `0`.
operator_reason: Explicit wrapping operator distinction.
0 — Attributes the difference to unspecified machine behavior.
... | ||
zig_005 | Catch expression type and fallback | Zig | Assume Zig 0.13.0. Does this compile?
```zig
fn f(x:anyerror!u8) u8 { return x catch 7; }
pub fn main() void { const a:u8=f(error.Bad); _=a; }
```
State the value assigned to `a`. | Apply Zig error-union and catch-expression semantics. | result: Compilation and assigned value.
0 — Says the error propagates from `f` or the program fails to compile.
1 — States that it compiles and `a` is 7.
catch_reason: Error-union unwrapping.
0 — Treats `catch` as executing only after a panic.
1 — Explains that `catch` unwraps a success payload or evaluates it... | ||
zig_006 | Pointer to local variable escape | Zig | Assume Zig 0.13.0. Is the pointer returned by `f` valid to dereference in the caller?
```zig
fn f() *const u8 { var x:u8=3; return &x; }
```
Give the compilation or lifetime diagnosis; do not assume an optimizer extension. | Apply Zig's compile-time escape analysis and lifetime rules. | diagnosis: Validity of escaping local address.
0 — Says the pointer safely refers to heap-promoted storage.
1 — States that returning a pointer to the local runtime variable is invalid and is rejected/diagnosed because the pointee's lifetime ends when `f` returns.
lifetime_reason: Storage duration.
0 — Claims Zi... | ||
zig_007 | Packed struct bit size | Zig | Assume Zig 0.13.0. What is `@sizeOf(T)`?
```zig
const T=packed struct { a:u3, b:u5, c:u8 };
```
Give the answer in bytes and explain why ordinary field alignment does not add padding. | Use Zig packed-struct layout rules. | size: Exact byte size.
0 — Gives anything other than 2 bytes.
1 — States `@sizeOf(T) == 2`.
layout_reason: Bit accounting.
0 — Adds ordinary struct padding between fields.
1 — Explains that the packed fields occupy 3+5+8=16 bits contiguously, yielding two bytes, without ordinary per-field alignment padding. | ||
zig_008 | Exhaustive enum switch | Zig | Assume Zig 0.13.0. Does this switch compile?
```zig
const E=enum{a,b,c};
fn f(e:E)u8{return switch(e){.a=>1,.b=>2};}
```
Give the decisive semantic requirement. | Apply Zig switch exhaustiveness rules. | compilation: Switch validity.
0 — Says unmatched `.c` implicitly traps or yields zero.
1 — States that compilation fails because `.c` is not handled and there is no `else`.
exhaustiveness: Required coverage.
0 — Treats enum switches as non-exhaustive statement constructs.
1 — Explains that a Zig `switch` must ... | ||
zig_009 | Optional orelse payload | Zig | Assume Zig 0.13.0. What exact text is printed?
```zig
const std=@import("std");
pub fn main() void {
const x:?u8=null;
const y=x orelse 9;
std.debug.print("{}",.{y});
}
``` | Give exact output and resulting type. | result: Output and value.
0 — Gives anything other than `9`.
1 — States that it prints `9` and `y` is an ordinary `u8`.
optional_reason: Fallback selection.
0 — Claims `y` remains null or has type `?u8` necessarily.
1 — Explains that `orelse` unwraps a present optional payload or evaluates the fallback for nul... | ||
zig_010 | Comptime type parameter and literal coercion | Zig | Assume Zig 0.13.0. Does this compile?
```zig
fn f(comptime T:type,x:T)T{return x;}
pub fn main()void{const x=f(u16,3);_ = x;}
```
State the inferred type and value of `x`. | Apply peer/type-context coercion for comptime integer literals. | result: Compilation, type, and value.
0 — Says the integer literal's default type forces `comptime_int` or `i32`.
1 — States that it compiles; `x` has type `u16` and value 3.
coercion_reason: Parameter context.
0 — Claims generic parameters cannot supply a coercion context.
1 — Explains that `T` is fixed at co... | ||
v_001 | V array assignment cloning | V | Assume V 0.4.10. What exact text is printed?
```v
fn main(){ mut a := [1,2,3]; b := a; a[0]=9; println('${a[0]} ${b[0]}') }
```
Explain V array assignment semantics. | Answer for V 0.4.10 language semantics. | exact_output: Exact line.
0 — Gives anything other than `9 1`.
1 — Gives exactly `9 1`.
copy_reason: Value semantics of arrays.
0 — Claims `b` necessarily aliases `a`'s mutable elements.
1 — Explains that ordinary V array assignment produces an independent array value/copy for this case, so mutating `a[0]` doe... | ||
v_002 | No implicit string-to-int conversion | V | Assume V 0.4.10. Does this compile?
```v
fn f(x int) int { return x+1 }
fn main(){ println(f('3')) }
```
State whether V performs the requested implicit conversion. | Use V's strict typing rules. | compilation: Argument type compatibility.
0 — Says the string is implicitly parsed as integer 3.
1 — States that it does not compile because a string cannot be passed where `int` is required without explicit conversion/parsing.
typing_reason: No implicit coercion.
0 — Predicts runtime parse failure.
1 — Explai... | ||
v_003 | Option fallback block | V | Assume V 0.4.10. What exact text is printed?
```v
fn f() ?int { return none }
fn main(){ x := f() or { 7 }; println(x) }
``` | Apply V option propagation/fallback semantics. | result: Exact output.
0 — Gives anything other than `7` or says an unhandled option aborts.
1 — States that it prints `7`.
option_reason: Role of the `or` block.
0 — Says `none` is converted to integer zero.
1 — Explains that `f` returns no value, so the `or` block supplies 7, which becomes the unwrapped integ... | ||
v_004 | Immutable array append | V | Assume V 0.4.10. Does this compile?
```v
fn main(){ a := [1,2,3]; a << 4 }
```
Explain the mutability requirement. | Apply V variable mutability rules. | compilation: Whether append is allowed.
0 — Says arrays are mutable regardless of binding.
1 — States that it fails to compile because `a` was not declared `mut`.
mutability_reason: Mutation of bound value.
0 — Treats `<<` as producing a new array without modifying `a`.
1 — Explains that `a << 4` mutates/appen... | ||
v_005 | V value receiver method | V | Assume V 0.4.10. What exact text is printed?
```v
struct S { x int }
fn (s S) val() int { return s.x }
fn main(){ s:=S{x:4}; println(s.val()) }
``` | Give exact output and receiver interpretation. | output: Exact output.
0 — Gives anything other than `4`.
1 — States that it prints `4`.
receiver_reason: Method receiver value access.
0 — Claims a mutable or pointer receiver is required merely to read a field.
1 — Explains that `(s S)` is a value receiver and may read the immutable field `x`; no mutation or ... | ||
v_006 | Generic type inference | V | Assume V 0.4.10. Does this compile?
```v
fn id[T](x T) T { return x }
fn main(){ x:=id(3); println(x) }
```
State the inferred type and output. | Apply V generic call inference for the stated version. | result: Compilation, type, output.
0 — Says explicit `[int]` is mandatory or gives a non-integer result.
1 — States that it compiles, infers `T` as `int`, and prints `3`.
inference_reason: Inference from argument.
0 — Claims the return context alone supplies an unrelated type.
1 — Explains that the integer arg... | ||
v_007 | Map missing-key fallback | V | Assume V 0.4.10. What exact text is printed?
```v
fn main(){ m:={'a':1}; println(m['b'] or { 9 }) }
``` | Apply V map indexing with an `or` fallback. | output: Exact line.
0 — Gives zero, an abort, or anything other than `9`.
1 — States that it prints `9`.
map_reason: Missing-key handling.
0 — Claims every missing integer map key silently returns zero even with `or`.
1 — Explains that key `b` is absent and the attached `or` block supplies the fallback value 9... | ||
v_008 | Implicit interface satisfaction | V | Assume V 0.4.10. Does this compile?
```v
interface Speaker { speak() string }
struct Dog {}
fn (Dog) speak() string { return 'woof' }
fn say(s Speaker){println(s.speak())}
fn main(){say(Dog{})}
```
State the output and whether an explicit declaration of conformance is needed. | Apply V interface satisfaction rules. | result: Compilation and output.
0 — Says `Dog` must explicitly declare `implements Speaker`.
1 — States that it compiles and prints `woof`.
interface_reason: Structural conformance.
0 — Treats V interfaces as requiring nominal inheritance.
1 — Explains that `Dog` implicitly satisfies `Speaker` by providing a c... | ||
v_009 | Block-scope defer captures variable | V | Assume V 0.4.10. What exact text is printed?
```v
fn main(){ mut x:=1; { defer { println(x) }; x=4 } }
```
State when the deferred block runs and what value it observes. | Track V defer execution at scope exit. | output: Exact output.
0 — Gives `1` or says defer waits until process exit.
1 — States that it prints `4`.
defer_reason: Scope and observed state.
0 — Claims the value is copied when `defer` is registered.
1 — Explains that the deferred block runs when the enclosing inner scope exits, after `x=4`, and observes... | ||
v_010 | Immutable-by-default local | V | Assume V 0.4.10. Does this compile?
```v
fn main(){ x:=3; x=4 }
```
If not, identify the exact declaration change needed. | Apply V local variable mutability syntax. | compilation: Assignment legality.
0 — Says ordinary locals are mutable by default.
1 — States that it fails because `x` is immutable.
fix: Minimal declaration change.
0 — Proposes changing the type or using a pointer.
1 — Identifies `mut x := 3` as the needed declaration for the later assignment. | ||
cuda_001 | Cross-warp communication with syncwarp | CUDA | Assume CUDA 12.x, compute capability 8.0, launch `k<<<1,64>>>(out)`. Is the claimed cross-warp result guaranteed?
```cpp
__global__ void k(int*out){__shared__ int s[2];unsigned t=threadIdx.x,w=t>>5,l=t&31;if(l==0)s[w]=100+w;__syncwarp();out[t]=s[w^1];}
```
Explain visibility, conflicting accesses, and the minimal colle... | Use CUDA's synchronization and memory-order rules, not likely scheduling. | guarantee: Correctness of cross-warp reads.
0 — Says `__syncwarp()` guarantees the exchange across both warps.
1 — States that the result is not guaranteed and the accesses form unsynchronized cross-warp read/write races.
fix: Minimal synchronization primitive.
0 — Suggests another `__syncwarp()` with the same p... | ||
cuda_002 | Warp ballot population count | CUDA | Assume CUDA 12.x and launch `k<<<1,32>>>(out)`. What value is guaranteed in `out[0]`?
```cpp
__global__ void k(int*out){unsigned m=__ballot_sync(0xffffffff,threadIdx.x%3==0);if(threadIdx.x==0)out[0]=__popc(m);}
``` | Compute the active-lane predicate exactly. | value: Exact population count.
0 — Gives anything other than 11.
1 — States that `out[0]` is 11.
lane_count: Predicate accounting.
0 — Counts only ten multiples or includes lane 32.
1 — Enumerates or correctly counts lanes 0,3,6,...,30: eleven active lanes whose ballot bits are set, and `__popc` returns 11. | ||
cuda_003 | Divergent block barrier | CUDA | Assume CUDA 12.x, compute capability 8.0, launch `k<<<1,64>>>`. Is this barrier use valid?
```cpp
__global__ void k(){if(threadIdx.x<32){__syncthreads();}}
```
State the precise consequence. | Apply collective barrier participation requirements. | classification: Validity of conditional barrier.
0 — Says the first warp may synchronize independently at `__syncthreads()`.
1 — States that the barrier is invalid because not all non-exited threads in the block reach it; behavior is undefined and may deadlock.
scope_reason: Block-wide nature.
0 — Treats `__sync... | ||
cuda_004 | Shuffle XOR partner lane | CUDA | Assume CUDA 12.x and launch `k<<<1,32>>>(out)`. What exact permutation is written?
```cpp
__global__ void k(int*out){unsigned x=threadIdx.x;out[x]=__shfl_xor_sync(0xffffffff,x,1);}
```
Give a formula for every lane. | State the exact lane mapping. | permutation: Exact value per lane.
0 — Gives a rotation or any mapping other than adjacent-pair exchange.
1 — States `out[x] = x ^ 1` for lanes 0 through 31: 0/1, 2/3, ..., 30/31 exchange values.
shuffle_reason: Meaning of XOR lane mask.
0 — Claims the operation XORs the data value with 1.
1 — Explains that la... | ||
cuda_005 | Atomic increment final value and ordering | CUDA | Assume CUDA 12.x. A kernel performs `atomicAdd(&counter,1)` on a global-memory `unsigned int counter` from each of exactly 1,000 threads, with no other counter accesses during the kernel. `counter` is initialized to 0 and does not overflow. After the kernel has completed and the host synchronizes, what value is guarant... | Separate atomic modification order from execution ordering. | final_value: Exact synchronized result.
0 — Gives any value other than 1000 or calls the final count nondeterministic.
1 — States the final value is guaranteed to be 1000.
ordering_scope: What atomicity does not imply.
0 — Claims the atomics impose a deterministic thread execution order or a block/global barrier... | ||
cuda_006 | CUDA built-in dimensions arithmetic | CUDA | Assume CUDA 12.x, launch `k<<<2,32>>>`, and `out` has two integers initialized to zero.
```cpp
__global__ void k(int*out){if(threadIdx.x==0)out[blockIdx.x]=gridDim.x*blockDim.x+blockIdx.x;}
```
After synchronization, what are `out[0]` and `out[1]`? | Compute exact built-in values for the launch. | values: Both exact values.
0 — Gives neither value correctly.
1 — Gives one of `out[0]=64` or `out[1]=65` correctly.
2 — States `out[0]=64` and `out[1]=65`.
launch_reason: Built-in variable substitution.
0 — Uses total threads as 32 or confuses block and thread indices.
1 — Explains `gridDim.x=2`, `blockDim.... | ||
cuda_007 | Threadfence block visibility scope | CUDA | Assume CUDA 12.x, compute capability 8.0. Is `__threadfence_block()` by thread 0 sufficient to make its preceding global-memory write visible to thread 0 of a different block that subsequently reads the location, absent any other synchronization? | Distinguish ordering scope from inter-block synchronization. | answer: Cross-block guarantee.
0 — Says the fence guarantees visibility to every block.
1 — States that no cross-block visibility/order guarantee follows; the reader may observe the old value and the unsynchronized accesses can race.
scope_reason: Fence scope and missing handshake.
0 — Treats any fence as a grid... | ||
cuda_008 | Warp shuffle reduction | CUDA | Assume CUDA 12.x, launch `k<<<1,32>>>(out)`. What value does lane 0 write?
```cpp
__global__ void k(int*out){unsigned x=threadIdx.x+1;for(int d=16;d>0;d>>=1)x+=__shfl_down_sync(0xffffffff,x,d);if(threadIdx.x==0)out[0]=x;}
``` | Compute the warp reduction exactly. | value: Exact reduction.
0 — Gives anything other than 528.
1 — States lane 0 writes 528.
reduction_reason: Sum represented by the shuffle stages.
0 — Sums lane indices 0 through 31 to 496 or ignores the +1.
1 — Explains that the shuffle-down tree accumulates initial values 1 through 32 in lane 0, whose sum is ... | ||
cuda_009 | UVA versus pageable host accessibility | CUDA | Assume CUDA 12.x. May a kernel directly dereference ordinary pageable host memory obtained by `malloc` merely because unified virtual addressing is enabled? Give the portable answer and distinguish address unification from memory accessibility. | Answer for portable CUDA behavior, not a platform-specific extension. | answer: Whether malloc memory is device-accessible.
0 — Says UVA makes every host pointer directly dereferenceable by a kernel.
1 — States that ordinary pageable `malloc` memory is not thereby device-accessible; direct kernel dereference is not portably valid.
uva_reason: Address-space naming versus allocation pro... | ||
cuda_010 | Global index and grid stride | CUDA | Assume CUDA 12.x and a one-dimensional launch. Give the canonical expression for the unique global linear thread index and the canonical grid-stride-loop increment. Then evaluate both for `blockIdx.x=3`, `blockDim.x=128`, `threadIdx.x=5`, `gridDim.x=20`. | Give formulas and exact evaluated integers. | index: Formula and value.
0 — Does not give `blockIdx.x * blockDim.x + threadIdx.x` or gives a value other than 389.
1 — Gives global index `blockIdx.x * blockDim.x + threadIdx.x = 389`.
stride: Formula and value.
0 — Does not give `blockDim.x * gridDim.x` or gives a value other than 2560.
1 — Gives grid strid... | ||
rust_011 | Mutable reborrow ending at last use | Rust | Assume stable Rust 1.85.0. Does this compile, and why?
```rust
fn main(){let mut x=0;let r=&mut x;let s=&mut *r;*s=1;*r=2;println!("{x}");}
``` | Apply non-lexical lifetimes and reborrowing. | result_and_reason: Compilation, output, and reborrow lifetime.
0 — Says overlapping mutable references necessarily reject the program or gives output other than 2.
1 — States that it compiles and prints 2; `s` is a reborrow of `r`, and its borrow ends after `*s=1`, allowing `r` to be used again under non-lexical li... | ||
rust_012 | Ref pattern avoids partial move | Rust | Assume stable Rust 1.85.0. What exact output is printed?
```rust
fn main(){let x=Some(String::from("a"));match x{Some(ref s)=>print!("{s}"),None=>{}}print!("{}",x.is_some());}
``` | Track match binding mode and ownership. | answer: Exact output and ownership reason.
0 — Says `x` is moved or gives output other than `atrue`.
1 — States it prints `atrue`; `ref s` borrows the inner String rather than moving it, so `x` remains usable after the match. | ||
rust_013 | Block constant evaluation | Rust | Assume stable Rust 1.85.0. Is this accepted?
```rust
const X:usize={let a=[1,2,3];a.len()};
fn main(){println!("{X}");}
```
Give the output and explain constant evaluation. | Apply stable const-evaluation rules. | answer: Compilation and output.
0 — Says local bindings are forbidden in const blocks or gives output other than 3.
1 — States it compiles and prints 3; the const initializer block is evaluated at compile time and array `len` is const-evaluable. | ||
rust_014 | Impl Trait Copy bound | Rust | Assume stable Rust 1.85.0. Does this compile?
```rust
fn f(_:impl Copy){}
fn main(){let s=String::from("x");f(s);}
```
Name the unsatisfied bound. | Give the concrete trait-bound diagnosis. | diagnosis: Exact bound failure.
0 — Says it compiles because arguments are moved by value.
1 — States it fails because `String` does not implement `Copy`; moving `s` is allowed in general but cannot satisfy the explicit `impl Copy` parameter bound. | ||
rust_015 | Rest pattern in fixed array | Rust | Assume stable Rust 1.85.0. What exact output is printed?
```rust
fn main(){let a=[10,20,30];let [x,..,y]=a;print!("{x}-{y}");}
``` | Apply array pattern binding semantics. | answer: Exact output and bindings.
0 — Gives anything other than `10-30`.
1 — States it prints `10-30`; `x` binds the first and `y` the last element, while `..` ignores the middle. | ||
go_011 | Deferred arguments versus closure capture | Go | Assume Go 1.23. What exact text is printed?
```go
package main
import "fmt"
func main(){x:=1;defer fmt.Print(x);x=2;defer func(){fmt.Print(x)}()}
``` | Track defer evaluation and LIFO order. | answer: Exact output and mechanism.
0 — Gives anything other than `21`.
1 — States it prints `21`: deferred calls run LIFO; the closure reads current `x=2`, while the earlier `fmt.Print` argument captured value 1 when deferred. | ||
go_012 | Append within capacity | Go | Assume Go 1.23. Is `len(s)` guaranteed to be 0 or 1 after this code?
```go
s:=make([]int,0,1);s=append(s,7)
```
Also state `cap(s)`. | Give exact slice length and capacity. | answer: Exact slice metadata.
0 — Gives length or capacity other than 1.
1 — States `len(s)==1` and `cap(s)==1`; append uses the available slot and returns a slice header with length increased by one. | ||
go_013 | Approximation element in constraint | Go | Assume Go 1.23. Does this compile?
```go
package p
type MyInt int
func f[T ~int](x T) int{return int(x)}
var _=f(MyInt(3))
``` | Apply type-set approximation syntax. | answer: Constraint satisfaction and result.
0 — Says only the predeclared type `int` satisfies `~int`.
1 — States it compiles and produces 3; `~int` includes defined types whose underlying type is `int`, including `MyInt`. | ||
go_014 | Buffered values after channel close | Go | Assume Go 1.23. What exact text is printed?
```go
package main
import "fmt"
func main(){c:=make(chan int,1);c<-5;close(c);a,ok1:=<-c;b,ok2:=<-c;fmt.Print(a,ok1,b,ok2)}
``` | Track receives from a closed buffered channel. | answer: Exact output and receive states.
0 — Gives anything other than `5true0false`.
1 — States it prints `5true0false`: closing preserves the queued 5 for the first receive; after the buffer drains, receive yields the zero value and `ok=false`. | ||
go_015 | Untyped constant overflow at assignment | Go | Assume Go 1.23. Does this compile?
```go
package main
func main(){const n=1<<100;var x int=n;_ = x}
```
Explain representability. | Apply arbitrary-precision constant and assignment representability rules. | diagnosis: Compilation and overflow point.
0 — Says the shift itself overflows or silently truncates.
1 — States it fails at conversion/assignment to `int`: the untyped constant `1<<100` can be represented as a constant, but is not representable by the implementation's `int` type on any permitted Go target. | ||
c_011 | C byte size versus bit width | C | Assume ISO C17. What is guaranteed about `sizeof(char)`, `sizeof(unsigned char)`, and `CHAR_BIT`? Is `CHAR_BIT==8` required? | Use ISO C terminology for bytes and bits. | answer: Exact size and bit-width guarantees.
0 — Says `sizeof(char)` may differ from 1 or that C requires 8-bit bytes.
1 — States `sizeof(char)==sizeof(unsigned char)==1`; `CHAR_BIT` is the number of bits in a byte and is at least 8, but need not equal 8. | ||
c_012 | Relational comparison of unrelated pointers | C | Assume ISO C17. Is this comparison defined, and is either result guaranteed?
```c
int a,b; int r=&a < &b;
``` | Distinguish pointer equality and relational operators. | classification: Relational comparison category.
0 — Calls it undefined behavior or gives a guaranteed boolean.
1 — States the comparison has an unspecified result for pointers to unrelated objects; neither true nor false is guaranteed, but evaluating it is not thereby undefined behavior. | ||
c_013 | Unsigned char increment wrap | C | Assume ISO C17. What exact integer does `f()` return?
```c
int f(void){unsigned char x=255;return ++x;}
``` | Apply integer promotions and conversion back on compound update. | answer: Exact return and arithmetic reason.
0 — Calls it signed overflow or gives 256.
1 — States it returns 0: `x` is promoted for addition, then the value 256 is converted back to `unsigned char`, wrapping modulo 256 under the stated 8-bit-value range implied by initial max 255. | ||
c_014 | Pointer representation across object pointer types | C | Assume ISO C17. Is `sizeof(int (*)[10])` required to equal `sizeof(int*)`? Give the portable conclusion. | Do not assume a flat ABI. | answer: Portable size relationship.
0 — Says all object pointer types are required to have the same size.
1 — States that C17 does not require a pointer to an array of 10 int to have the same size/representation as `int*`; equality is common but not portable. | ||
cpp_011 | Mutable lambda value capture | C++ | Assume ISO C++20. What exact output is printed?
```cpp
#include <iostream>
int main(){int x=1;auto y=[x]()mutable{return ++x;};std::cout<<y()<<y()<<x;}
``` | Track captured and outer state. | answer: Exact output and state separation.
0 — Gives anything other than `231`.
1 — States it prints `231`: the mutable closure increments its private captured copy from 1 to 2 then 3; outer `x` remains 1. | ||
cpp_012 | Guaranteed copy elision with deleted copy | C++ | Assume ISO C++20. Does this compile?
```cpp
struct A{A()=default;A(const A&)=delete;};
A f(){return A{};}
int main(){A a=f();}
``` | Apply mandatory prvalue materialization rules. | answer: Compilation and copy-elision rule.
0 — Says the deleted copy constructor makes either return or initialization ill-formed.
1 — States it compiles: the prvalue `A{}` initializes the function result directly, and `f()` initializes `a` directly under guaranteed copy elision, so no copy constructor is odr-used. | ||
cpp_013 | Competing standard conversions | C++ | Assume ISO C++20. Which overload is selected?
```cpp
void f(long);void f(double);
int main(){f(1);}
``` | Apply overload conversion ranking. | answer: Overload resolution result.
0 — Selects either overload as uniquely better.
1 — States the call is ambiguous: `int` to `long` and `int` to `double` are both standard conversion sequences of conversion rank, with neither better. | ||
cpp_014 | Character literal type in C++ | C++ | Assume ISO C++20. What does `sizeof('a')` equal, in units of bytes? Contrast this with C. | Answer for C++20 and note the requested C contrast. | answer: C++ value and C distinction.
0 — Says C++ ordinary character literals have type `int`.
1 — States `sizeof('a') == 1` in C++ because `'a'` has type `char`; in C an ordinary character constant has type `int`, so its size is `sizeof(int)`. | ||
zig_011 | Zig bit size versus ABI size | Zig | Assume Zig 0.13.0. What are `@bitSizeOf(u7)` and `@sizeOf(u7)`? | Give exact bit and byte quantities. | answer: Exact two values.
0 — Does not give both 7 bits and 1 byte.
1 — States `@bitSizeOf(u7)==7` and `@sizeOf(u7)==1` byte. | ||
zig_012 | Mutable pointer coercion to const | Zig | Assume Zig 0.13.0. Does this compile?
```zig
fn f(x:*const u8)u8{return x.*;}
pub fn main()void{var x:u8=4;const y=f(&x);_ = y;}
``` | Apply pointer constness coercion. | answer: Compilation and value.
0 — Says `*u8` cannot be passed as `*const u8`.
1 — States it compiles and `y==4`; a mutable pointer may coerce to a const pointer for read-only access. | ||
zig_013 | Typed left shift | Zig | Assume Zig 0.13.0. What exact value does this compile-time expression produce?
```zig
const x=@as(u8,3)<<2;
``` | Give exact type and value. | answer: Exact value and type.
0 — Gives a value other than 12 or a type other than u8.
1 — States `x` has type `u8` and value 12. | ||
zig_014 | Tagged union inactive field assignment | Zig | Assume Zig 0.13.0. Does this compile?
```zig
const U=union(enum){a:u8,b:u16};
pub fn main()void{var u=U{.a=3};u.b=4;}
```
Classify the direct field assignment when `.a` is active. | Apply tagged-union active-field safety rules. | diagnosis: Legality of assigning inactive field directly.
0 — Says direct assignment switches the active tag to `.b`.
1 — States the code is invalid/traps under safety because `.b` is not the active field; switching variants requires assigning a whole union value such as `u=U{.b=4}`. | ||
v_011 | V string byte length | V | Assume V 0.4.10. What exact output is printed?
```v
fn main(){ s:='abc'; println(s.len) }
``` | Give exact output for ASCII input. | answer: Exact output and unit.
0 — Gives anything other than 3.
1 — States it prints 3; for this ASCII string the byte length is three. | ||
v_012 | Mutable field on immutable struct binding | V | Assume V 0.4.10. Does this compile?
```v
struct S { mut: x int }
fn main(){ s:=S{}; s.x=1 }
```
Account for both field and variable mutability. | Apply V nested mutability requirements. | answer: Compilation and minimal fix.
0 — Says the mutable field declaration alone permits mutation through immutable `s`.
1 — States it fails because `s` itself is immutable; declare `mut s := S{}` (with the field already in `mut:`) to permit `s.x=1`. | ||
v_013 | V array slice length | V | Assume V 0.4.10. What exact output is printed?
```v
fn main(){ a:=[1,2,3]; println(a[1..].len) }
``` | Evaluate slice bounds exactly. | answer: Exact result.
0 — Gives anything other than 2.
1 — States it prints 2 because the slice from index 1 to the omitted exclusive end contains elements 2 and 3. | ||
v_014 | V if expression value | V | Assume V 0.4.10. Does this compile?
```v
fn main(){ x:=if true {1}else{2}; println(x) }
```
Give the output and classify `if` here. | Apply V expression typing. | answer: Compilation, output, expression form.
0 — Says V `if` cannot yield a value or gives output other than 1.
1 — States it compiles and prints 1; the `if` is used as an expression and both branches yield compatible integer values. | ||
cuda_011 | Warp broadcast from lane zero | CUDA | Assume CUDA 12.x and launch `k<<<1,32>>>(out)`. What does lane 7 write?
```cpp
__global__ void k(int*out){int x=threadIdx.x;out[x]=__shfl_sync(0xffffffff,x,0);}
``` | Compute the exact shuffle source. | answer: Exact written value.
0 — Gives anything other than 0.
1 — States lane 7 writes 0 because every participating lane reads lane 0's value. | ||
cuda_012 | Fence without execution synchronization | CUDA | Assume CUDA 12.x. Within one block, thread 0 writes shared memory, calls `__threadfence_block()`, and thread 1 reads without a barrier or atomic handshake. Is the read guaranteed to see the write? | Separate a fence from a collective barrier. | answer: Visibility guarantee.
0 — Says the fence alone forces thread 1 to wait and observe the write.
1 — States the read is not guaranteed and the accesses remain unsynchronized; `__threadfence_block()` orders the calling thread's memory operations but is not an execution barrier or handshake. | ||
cuda_013 | CUDA launch cardinality | CUDA | Assume CUDA 12.x and launch `k<<<3,10>>>(out)`. How many threads execute the kernel body, and what is the maximum one-dimensional global index `blockIdx.x*blockDim.x+threadIdx.x`? | Give exact count and maximum index. | answer: Both exact integers.
0 — Gets both values wrong.
1 — Gives either 30 threads or maximum index 29.
2 — States 30 threads execute and the maximum global index is 29. | ||
cuda_014 | Block barrier is not grid barrier | CUDA | Assume CUDA 12.x. Is `__syncthreads()` a grid-wide barrier when a kernel has multiple blocks? If not, can it by itself make a producer in block 0 safely hand data to a consumer in block 1 within the same kernel launch? | State synchronization scope and consequence. | answer: Scope and cross-block consequence.
0 — Calls it grid-wide or says matching calls in both blocks synchronize with each other.
1 — States `__syncthreads()` synchronizes only threads of one block and cannot by itself implement a safe block-0 to block-1 handoff; separate kernel launches, cooperative-grid synchr... |
Coding-Corpus-Bench
A benchmark dataset for evaluating language-semantics reasoning across systems programming and low-level programming languages.
Overview
Coding-Corpus-Bench contains 100 curated programming-language questions designed to test whether a model can reason precisely about language semantics rather than rely on superficial pattern matching or observed behavior.
The benchmark covers:
- Rust
- Go
- C
- C++
- Zig
- V
- CUDA
Questions focus on subtle semantic rules including ownership, lifetimes, type systems, overload resolution, memory models, evaluation order, synchronization, representation validity, and compiler behavior under explicitly stated language/toolchain versions.
Each example provides both a question and a rubric describing the reasoning and conclusion expected from a high-quality answer.
Dataset Statistics
| Language | Examples |
|---|---|
| Rust | 15 |
| Go | 15 |
| C | 14 |
| C++ | 14 |
| Zig | 14 |
| V | 14 |
| CUDA | 14 |
| Total | 100 |
Dataset Format
The dataset is provided as JSONL. Each line represents one benchmark item.
{
"id_aa": "rust_001",
"title": "GAT higher-ranked implied static",
"category": "Rust",
"prompt": "...",
"system_prompt": "...",
"rubric": "...",
"expected_deliverables": "",
"reference_files": ""
}
Fields
| Field | Description |
|---|---|
id_aa |
Unique identifier for the benchmark item. |
title |
Short description of the semantic issue being tested. |
category |
Programming language or platform category. |
prompt |
The question presented to the model, often including a code fragment and explicit version assumptions. |
system_prompt |
Task-specific instruction describing the required reasoning perspective. |
rubric |
Evaluation criteria for judging the answer. |
expected_deliverables |
Reserved field for expected deliverables; currently empty for all examples. |
reference_files |
Reserved field for supporting references; currently empty for all examples. |
What the Benchmark Tests
The corpus emphasizes questions where a superficially plausible answer can be wrong without precise knowledge of the language specification.
Rust
Examples cover topics such as:
- Generic associated types and higher-ranked trait bounds
- Lifetime inference and implied
'staticrequirements - Drop timing
- Wildcard patterns
- Method-call receiver adjustment and autoref
- Closure capture and closure traits
- Two-phase borrows
- Trait coherence
ManuallyDrop- Type validity and undefined behavior
- Trait-object method dispatch
Self: Sizedand dyn compatibility- Non-lexical lifetimes
- Borrowing through
refpatterns - Compile-time evaluation
- Trait bounds
Go
Examples test areas including:
selectoperand evaluation- Typed nil values inside interfaces
- Slice range semantics
- Generic type sets
- Named return values and
defer - Channel synchronization and happens-before
- Method sets
- Buffered-channel synchronization
- Deferred argument evaluation
- Slice capacity
- Approximation elements such as
~int - Closed-channel receive semantics
- Untyped constants and representability
C
Examples address ISO C semantics such as:
- Object representation and byte size
CHAR_BIT- Relational comparison of pointers
- Integer promotions
- Unsigned arithmetic
- Pointer representation and object-pointer sizes
C++
Examples cover:
- Mutable lambda captures
- Guaranteed copy elision
- Deleted copy constructors
- Overload resolution
- Character literal types
Zig
Examples cover:
- Bit size versus ABI size
- Pointer constness coercion
- Typed shifts
- Tagged-union active-field rules
V
Examples cover:
- String byte length
- Mutability of struct fields and bindings
- Array slicing
ifexpressions
CUDA
Examples cover:
- Warp shuffle operations
- Memory fences versus execution synchronization
- Kernel launch cardinality
- Block-level versus grid-level barriers
Version-Specific Reasoning
Questions explicitly state the relevant language or toolchain version where the answer depends on version-specific semantics.
Examples include:
- Rust 1.85.0, edition 2021
- Go 1.23
- ISO C17
- ISO C++20
- Zig 0.13.0
- V 0.4.10
- CUDA 12.x
Evaluations should therefore be performed against the assumptions stated in each individual item rather than against an unspecified "latest" language version.
Evaluation
The rubric field contains the expected evaluation criteria.
Rubrics generally distinguish between:
- The final conclusion — whether code compiles, what it prints, whether behavior is defined, etc.
- The decisive reasoning — whether the answer identifies the particular language rule responsible for that conclusion.
For example, a benchmark item may require both:
- the exact output; and
- an explanation of why evaluation order, borrowing, synchronization, or destructor timing produces that output.
This makes the dataset suitable for evaluating reasoning quality, not merely final-answer accuracy.
Example
A Rust item concerning a reborrow expects the answer to recognize that the program compiles because the reborrow's lifetime ends at its last use under non-lexical lifetimes, rather than incorrectly rejecting the program merely because two mutable references appear in the same scope.
Intended Uses
The dataset can be used for:
- Evaluating LLM coding and reasoning models
- Testing language-semantics competence
- Comparing models across programming languages
- Building automated benchmark/evaluation pipelines
- Studying hallucination and specification-reasoning errors
- Evaluating whether models provide decisive explanations rather than unsupported conclusions
Recommended Evaluation Protocol
For each item:
- Provide the
promptto the model under the assumptions stated in the prompt. - Preserve the relevant language/toolchain version.
- Evaluate the response against the associated
rubric. - Score the requested conclusion separately from the supporting reasoning where the rubric provides separate criteria.
- Do not award correctness merely because a model happens to give the expected output without explaining the semantic rule when the rubric explicitly requires that explanation.
Data Integrity
The supplied corpus contains:
- 100 benchmark items
- 7 language/platform categories
- An empty
expected_deliverablesfield for every item - An empty
reference_filesfield for every item
The benchmark is therefore self-contained at the example/rubric level; no external reference files are specified by the dataset entries themselves.
License
Open Data Attribution Training Disclosure License (ODATL‑1.0)
- Downloads last month
- -