Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Fix a build that fails inside a template

Use when: the first error: points into a template's body or a library header, and the output runs to pages of required from here, requested here and note: candidate lines

Goal: the one line of your own code that caused the error, and whether to change the type you passed or the call you made

Taught in Reading template errors · extends Fix a build that won't compile

  1. 1

    Same first move as any build failure: skip to the first line that says error: and read its message. Ignore the length of the output.

    Example

    In GCC's 374 lines for print_all(points), the first error is line 3: main.cpp:12:19: error: no match for 'operator<<' (operand types are ... and 'const Point'). Something tried to print a Point.

    Why: every template error has one real error: line; everything else is context or candidates.

  2. 2

    Look for the type the template was filled in with. GCC writes [with T = ...]; Clang writes the type in angle brackets, like print_all<Point>.

    Example

    GCC: In instantiation of 'void print_all(const std::vector<T>&) [with T = Point]'. Clang: in instantiation of function template specialization 'print_all<Point>'. Both say T is Point.

    Why: the template's code is fine for some types. The error is about this particular T.

  3. 3

    Find the line in your file that asked for this template. GCC prints it before the error, ending required from here. Clang prints it after the error, as a note ending requested here.

    Example

    GCC: main.cpp:18:14: required from here. Clang: main.cpp:18:5: note: ... requested here. Line 18 is print_all(points);, the call in main.

    Why: the error line may sit in a header you never wrote. Your line is the one you can change.

  4. 4

    Check whether the template has a concept on it.

    Example

    Constrained version: Clang's last note is because 'out << value' would be invalid. The missing requirement is "a Point can be printed with <<."

    • the first error is "no matching function" at your own line, followed by constraints not satisfied — the template is constrained. Read down the chain of notes to the last one (the required expression ... is invalid on GCC, because ... would be invalid on Clang). It names the exact requirement your type is missing.
    • the first error is inside the template's body — the template is unconstrained. The error line itself is the requirement: the operation the body tried on your T.

    Why: a concept is checked at the call, before the body is written out, so its notes say which requirement failed in plain terms.

  5. 5

    Decide which side is wrong. Either give the type what the template needs, or stop passing that type. Then rebuild and start again from Step 1 if anything is left.

    Example

    Either give Point an operator<<, or don't call print_all on points. In the second worked example below, the fix is on the type: name() becomes name() const.

    ⚡ Shortcut

    Skip the note: candidate lines unless Steps 1–4 didn't explain the error. They're usually most of the output (53 of them in GCC's 374 lines here), and they only confirm that no existing overload accepts your type.

    Why: the template states what it needs, so the fix belongs to whichever side broke that agreement.

Common mistakes

  • Reading the output top to bottom, starting with the candidate list.
  • Editing the library header the error points into, instead of your own call or your own type.
  • Assuming GCC and Clang put things in the same order. GCC shows your line before the error, Clang after.
  • Stopping at the first note of a constraint chain instead of reading down to the last one.