All guides
Every guide, newest first. Browse by topic instead, or read the daily tips and puzzles.
-
Fix C++ "Use of Deleted Function" — Copying a unique_ptr Holder, Deleted Copies, and Deleted Overloads C++
GCC stops the build with 'use of deleted function' when a copy, a call, or an overload lands on a function the program must not use. This guide reproduces the message exactly as GCC 13.3.0 prints it for four shapes: a class holding a std::unique_ptr whose copy constructor is implicitly deleted, a copy constructor deleted with = delete, a std::unique_ptr passed by value, and an overload set where the deleted overload is the best match — and gives the fix that belongs to each shape: std::move, a clone, a const reference, and removing the deleted overload or converting the argument.
-
Fix C++ shared_ptr Cycle Leak — Two Objects Keep Each Other Alive, weak_ptr Breaks the Cycle C++
Two objects that hold std::shared_ptr to each other never get destroyed: each count stays at 1 after every outside pointer is gone, no destructor runs, and no error appears. This guide reproduces the leak with a Parent and a Child that own each other, proves it with a std::weak_ptr observer that still reports use_count 1 and expired false after the scope ends, and fixes it by making the Child-to-Parent link a std::weak_ptr, after which both destructors run and the observer reports expired true.
-
Fix C++ Deadlock with std::scoped_lock — Two Mutexes, Opposite Order, One Hang C++
A program that locks two mutexes in opposite order in two threads can hang forever: each thread holds one mutex and waits for the other, and neither wait ever ends. This guide reproduces that hang with two accounts, two mutexes, and a 100 millisecond pause that makes the deadlock happen every run, shows one hung run's output before timeout kills it with status 124, and fixes it twice: once with std::scoped_lock locking both mutexes in one call in both threads, and once by locking in one consistent order everywhere, with the measured exit status for each run.
-
Fix LeakSanitizer "Detected Memory Leaks" — Direct vs Indirect Leaks, Traced to the Owner Sysadmin
LeakSanitizer ends a program with 'detected memory leaks' when heap memory is still allocated at exit and no pointer to it remains. This guide reproduces a direct leak and a linked indirect leak exactly as GCC 13.3.0 prints them, reads the direct and indirect sections and the SUMMARY line, traces each allocation stack to the object that should own the memory, and fixes the leak by giving every allocation an owner, with the measured exit status, the detect_leaks switch, and the suppression form for leaks not yours to fix.
-
Fix Go "Undefined: ..." Compile Errors — Identifiers, Scope, and Package Qualifiers Go
Go prints undefined: name when a name in the code has no declaration in scope at the point where it is used, and the name after the colon is the whole diagnosis. This guide reproduces that message exactly as Go 1.26.4 prints it and works through the shapes that produce it: a name that was never declared, a typo or a change of letter case — Go identifiers are case-sensitive, and the first letter also decides whether a package member is exported — a local variable used before its declaration, because a local variable's scope begins at the end of its declaration statement, a variable used after the block, if, or for statement that declared it has ended, a missing package qualifier such as Println without fmt., a missing import, which makes the package name itself undefined, and a renamed import used under its old name — ending with the contrasts that separate this error from its look-alikes: a function may call another function declared later in the file because package-level scope covers the whole package, and an inner declaration that shadows an outer name compiles without any message at all.
-
Fix Go "Too Many Arguments" and "Not Enough Arguments in Call" — Call Arity, Variadic Functions, and the Spread Operator Go
Go counts the arguments at every call against the function's parameter list and refuses to compile when the counts differ, printing the numbers it found and the numbers it wanted. This guide reproduces those messages exactly as Go 1.26.4 prints them and works through the shapes that produce them: an extra argument to an ordinary function, a missing argument, an argument passed to a function that takes none, an extra argument to a method or to a function value, a second argument to the built-in len, a variadic function called with no arguments for its fixed parameter, a slice passed to a variadic function without the spread operator, and the spread operator used on a function that is not variadic — ending with the contrasts that separate these errors from their look-alikes: a variadic function takes zero arguments for its variadic parameter, a slice spreads only with ..., and a call that passes another call's return values directly is the one exception to the count.
-
Fix Go "No Required Module Provides Package" — Module Resolution, Typos, Cycles, and the Replace Fix Go
Go refuses to build when an import names a package no module provides, printing 'no required module provides package' with the command that would add it. This guide reproduces those messages exactly as Go 1.26.4 prints them and works through the shapes that produce them: a missing go.mod file, an imported package with no requirement, a misspelled standard package, an import cycle between two local packages, and a lookup switched off by GOPROXY — ending with the fixes that belong to each shape: go mod tidy, go get, a replace directive to a local module, and the subpackage that needs no requirement at all.
-
Fix Go "missing return at end of function" — Return Paths, Named Results, and Branch Coverage Go
Go prints missing return when a function that declares result parameters can reach the end of its body without returning a value, and the position it prints is the function's closing brace. This guide reproduces that message exactly as Go 1.26.4 prints it and works through the shapes that produce it: a function with result parameters and no return at all, an if/else where one branch returns and the other falls through, a switch whose cases return but which has no default and no return after it, a return that sits only inside a for loop body, named result parameters where a bare return is legal on one path and a missing return is the defect on another, and a return hidden inside a nested block or an if initializer — ending with the contrasts that separate this error from its look-alikes: a function with no result parameters needs no return, a bare return with named results is legal, and Go has no implicit return at the end of a function.
-
Fix Go "Cannot Assign To ..." Compile Errors — Addressability, Map Values, Constants, and Call Results Go
Go refuses an assignment when the left-hand side has nowhere to store a value, printing 'cannot assign to' with the reason in parentheses. This guide reproduces those messages exactly as Go 1.26.4 prints them and works through the shapes that produce them: a field of a struct stored in a map, a constant, a function call's return value, a field of a composite literal, a character of a string, a field of a call's return value, a pointer method called on a map value, and a conversion or built-in call used as a target — ending with the contrasts that separate these errors from their look-alikes: a map index itself is a legal target, a map index increments fine, and a slice element or a dereferenced pointer takes an assignment.
-
Fix CMake "Generator Does Not Match" and Stale-Cache Errors When Switching Ninja and Make C++
Reconfiguring an existing build tree with a different generator fails with Error: generator : Unix Makefiles Does not match the generator used previously: Ninja — and a copied or moved build tree fails differently, with The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created. Both errors come from what the first configure pinned in CMakeCache.txt: the generator, the source directory, and the compiler. This guide reproduces both errors verbatim, reads the cache entries that cause them, and fixes them the two clean ways — a fresh build directory per generator, and removing CMakeCache.txt and CMakeFiles — plus the --fresh shortcut that performs that removal, and why editing the cache by hand is not a third fix.
-
Fix CMake "Could NOT Find a Package" — and When FetchContent Is the Right Fallback C++
Configure fails with Could not find a package configuration file provided by "Greet" — even though the Greet library is built and installed, with a GreetConfig.cmake on disk. This guide reads that error line by line: the module-mode paragraph, the two config file names CMake looked for, and the remedy sentence that names both native fixes. It fixes the search the native way first, with CMAKE_PREFIX_PATH and with Greet_DIR, and then shows the FetchContent fallback for the different case where no package config file exists at all, building the dependency from its sources instead.
-
Fix CMake "Cannot Find Source File" and "No SOURCES Given to Target" C++
Configure fails with two errors — Cannot find source file: src/main.cpp, and No SOURCES given to target: app — after a source file is renamed and CMakeLists.txt still lists the old name. This guide reproduces both errors, shows the exact path CMake builds from a relative source name by resolving it against CMAKE_CURRENT_SOURCE_DIR, and explains why the second error is a knock-on of the first rather than a second bug. It then shows the other way to earn the No SOURCES error on its own: a source list that expands to nothing, through a file(GLOB) pattern that matches no files, with the empty expansion printed and fixed.
-
Reading an AddressSanitizer Heap-Use-After-Free — Fault, Freed-By, Allocated-By Sysadmin
An AddressSanitizer heap-use-after-free report is the only common sanitizer report with three stacks, and all three earn their place: the fault stack names the line that read through the dangling pointer, the freed-by stack names the line that ended the object's lifetime, and the previously-allocated-by stack names the line that began it. Read together, the three stacks reconstruct the object's whole life and pinpoint the lifetime bug — a use that outlived the delete. This guide frees a heap int and reads it back, reads the full report stack by stack, and fixes the bug by extending the lifetime so the program runs clean under the sanitizer.
-
Reading an AddressSanitizer Heap-Buffer-Overflow — READ vs WRITE, Traced and Fixed Sysadmin
An AddressSanitizer heap-buffer-overflow report looks dense, but three lines in it do most of the work: the access line (WRITE of size 4, or READ of size 4), the fault stack that names the function and line that made the access, and the region line (0 bytes after 16-byte region) that says how far past the allocation the access landed. This guide writes one element past a four-element heap array, reads the full report line by line to the exact index, shows the same bug as a read so the READ and WRITE forms can be compared directly, works out the index arithmetic behind the region line, and fixes the bound so the program runs clean under the sanitizer.
-
Fix Go "No New Variables on Left Side of :=" — Redeclaration, Scope, and Shadowing Go
Go refuses a short variable declaration when every non-blank name on its left side already exists in the same scope, and it prints one sentence for the refusal: no new variables on left side of :=. This guide reproduces that sentence exactly as Go 1.26.4 prints it, states the redeclaration rule behind it — a short declaration may redeclare a variable only in a multi-variable form, only when the earlier declaration stands in the same block with the same type, and only when at least one non-blank variable on the left side is new — and works through the cases that decide real code: the plain assignment fix and the two ways assignment itself fails, the mixed form that redeclares an error variable beside a new result, the blank identifier, which never counts as new, a repeated name on the left side, and the scope boundary where the same spelling stops being a redeclaration and becomes a new variable instead — an outer-block or package-level name, an inner block, and the if, for, and switch initializers — ending with the shadowing trap, where an inner := takes the writes and the outer variable keeps its old value, and the package-level :=, which is a syntax error rather than a declaration at all.
-
Fix Go "Declared and Not Used" and "Imported and Not Used" Compile Errors Go
Two Go compile errors stop a build over code that harms nothing at run time: a local variable that is declared and never read, and an import that no identifier in the file ever names. This guide reproduces both errors exactly as Go 1.26.4 prints them — declared and not used: x, and "fmt" imported and not used — states the precise scope of each rule, and separates the cases that look alike but are not: assignment is not a use, while printing, passing, comparing, returning, incrementing and compound assignment all are; function parameters, named results, package-level declarations, struct fields and constants sit outside the variable rule entirely. It covers the blank identifier as the deliberate discard, its limits — it cannot rescue an import — the blank import form reserved for side-effect imports, multi-value declarations where only one value is wanted, variables declared in if and for headers, and the fixes ranked in the order to reach for them: use the value, remove the declaration, blank-assign only when the discard is the intent.
-
Fix Go "Cannot Use ... As ..." Type Errors — Assignability, Conversions, and Untyped Constants Go
Go assigns a value to a differently typed variable only when the language's assignability rule allows it, and every refusal arrives in one sentence: cannot use X as T value in a named place. This guide reproduces that sentence exactly as Go 1.26.4 prints it — for an untyped string constant given to an int, an int variable given to a string, a struct value, and the same refusal in an assignment, a call argument, and a return statement — states the assignability rule behind it (identical types, identical underlying types with at least one side unnamed, interface satisfaction, nil, and representable untyped constants), and works through the cases that decide real code: two named types over one underlying type, which are not assignable to each other; untyped constants, which pass at 3.0 and fail at 3.9 with a truncated note and at 300 into an int8 with an overflows note; the absence of implicit numeric conversion, even from int64 to int; explicit conversions, including the string(65) trap that yields one rune instead of digits; slice invariance, where []int is not []any; and interface failures that name the missing method.
-
Fix Go "Assignment Mismatch" and "Multiple-Value in Single-Value Context" Errors Go
Go functions return several values at once, and the compiler counts both sides of every assignment that receives them. This guide reproduces the two counting errors exactly as Go 1.26.4 prints them — assignment mismatch: 1 variable but pair returns 2 values, and multiple-value pair() in single-value context — states the tuple-assignment rule behind them (a multi-valued operation fills several variables only when it stands alone on the right side), and separates the places that look alike but follow different rules: the pass-through call f(g()), the return pass-through, a call used as a statement, and the three built-in operations — map index, type assertion, channel receive — that yield one value or two depending on how many variables receive them. It covers the mixed-list trap, where a two-value call beside another expression counts as one right-hand entry, the neighboring count checks with different messages (call arguments and return statements), and the fixes in order: bind every value, blank the ones that are unwanted on purpose, or pass the values through untouched.
-
Fix "Undefined Reference to Vtable" — the Missing Virtual Function C++
A class with virtual functions compiles in every file and then fails to link with a single undefined reference to the vtable for the class, naming no function at all. This guide reproduces that error, explains why the vtable is emitted alongside one particular member function — the first non-inline virtual, called the key function — and shows how to find which declared virtual was never defined. It covers the three fixes (define the function, make it pure virtual, define it inline), the nm check that proves where the vtable went missing, and the destructor variant whose error names the destructor and the typeinfo instead.
-
Fix Template "Undefined Reference" — Why Template Definitions Cannot Hide in a .cpp C++
A class template declared in a header and defined in a .cpp file compiles in both files and then fails to link with undefined references to every member the program uses. This guide reads the linker output, explains why the using file cannot generate the code and the defining file never does, and fixes it two ways: the definitions move into the header, or explicit instantiation in the .cpp turns the template into a closed set of types. It also shows the trap that follows the second fix — the first new type brings the same error back — and the member that never needed a definition at all.
-
Fix "Multiple Definition" Link Errors — Header Definitions and inline C++
A function and a variable defined in a header included by two source files fail to link with multiple definition errors for both. This guide reads the linker output line by line, traces it to the One Definition Rule, and fixes the header two ways: inline on the function and the variable, and a declaration in the header with the single definition in one source file. It also shows the static trap, where the link succeeds and each file silently gets its own counter.
-
Fix "Cannot Find -l..." — How ld Searches for Libraries, and Where the Path Is Set C++
The link fails with a single line — cannot find -lgreet — even though the library file is sitting in the project. This guide reproduces that error with a small library built in a lib directory, shows the exact filename the linker constructs from a -l option and the directories it searches for that name, and separates the three causes the one line hides: the file is not there, the name does not match, or the directory is not on the search path. It covers the -L fix, the full-path fix, the CMake find_library form, and the shared-library variant where the same command starts linking and the failure moves to program start instead.
-
Python uuid — uuid4, uuid5, Namespaces, and Parsing Python
Python uuid from the ground up: generate a random identifier with uuid4, derive a repeatable one with uuid5 and uuid3 from a namespace and a name, read the fields, int, bytes, and hex forms of a UUID, parse strings, bytes, and integers back into equal objects, and use UUIDs as dictionary keys and sorted values.
-
Python tarfile — Create, List, and Extract Tar Archives Python
Python tarfile from the ground up: build a tar archive in memory with TarInfo and addfile, list members with getmembers, getnames, and getmember, read contents back with extractfile, open plain and compressed archives with the w, w:gz, w:bz2, w:xz, and r:* modes, walk members with next, extract safely with the data filter, and handle the traversal, link, and read errors an untrusted archive can raise.
-
Python struct — Pack and Unpack Binary Data Python
Python struct from the ground up: pack values into bytes and unpack bytes back with struct.pack and struct.unpack, control byte order, size, and alignment with the @, =, <, >, and ! prefixes and calcsize, use the integer, float, char, string, pad, and Pascal format characters, handle the exact-size unpack error, write into a buffer with pack_into and unpack_from, and reuse a format with the Struct class and iter_unpack.
-
Python shlex — Split, Quote, and Join Shell-Like Strings Python
Python shlex from the ground up: split a command line with shell-like quoting using shlex.split, compare POSIX and non-POSIX modes, build a command string safely with shlex.quote and shlex.join, drive the shlex lexer class with comments, whitespace_split, and punctuation_chars, and handle the no-closing-quotation error and the single-quote backslash trap.
-
Python calendar — Month, Weekday, and Leap Year Python
Python calendar from the ground up: find a weekday with calendar.weekday, read a month's first weekday and length with monthrange, test leap years with isleap and leapdays, build week rows with monthcalendar, iterate days and dates with the Calendar class, print a month with TextCalendar, and set the first weekday with setfirstweekday.
-
Python base64 — Encode and Decode Bytes, URL-Safe Text, and Base85 Python
Python base64 from the ground up: encode bytes with b64encode and decode them back, read the padding, switch to the URL-safe alphabet or a custom one, wrap output for email with encodebytes, use the Base32 and Base16 forms, shrink output with Base85 and Ascii85, and handle the validation, padding, and text-input errors.
-
Python urllib.parse — URLs, Queries, and Quoting Python
Python urllib.parse from the ground up: split a URL into scheme, host, port, path, query, and fragment with urlparse and urlsplit, resolve a relative link with urljoin and its trailing-slash trap, read a query string with parse_qs and parse_qsl, build one with urlencode, quote and unquote text for a URL, rebuild a changed URL with _replace and urlunsplit, and handle the invalid-port errors.
-
Python ipaddress — Networks, Hosts, and Subnets Python
Python ipaddress from the ground up: build addresses, networks, and interfaces with ip_address, ip_network, and ip_interface, read a network's address, broadcast, netmask, and size, test containment, subnet and supernet a network, work with IPv6 compression and scope, compare and sort addresses, collapse a list of networks, and handle the strict host-bits trap and the invalid-address errors.