C++ Guides

GCC 16 Defaults to C++20: What Breaks in Your Old Code

GCC 16 changed the default C++ standard from gnu++17 to gnu++20. Code that never pinned a standard now compiles as C++20, and some of it does not compile at all. This guide takes a small legacy codebase — five C++17-era idioms in one file — and runs it under GCC 16.2.0 with default flags, under -std=c++17, and under GCC 13. The default build fails with 6 error lines for 5 distinct breakages. The C++17 build and the GCC 13 build both run and return the same answer. Every error below is quoted verbatim from the run, and the three items a migration checklist would wrongly list as breakages are corrected with the runs that disprove them.

Written November 7, 2026 · Tested with GCC 16.1 · 16 min read

By the end of this guide
  • The default moved
  • The legacy mini-codebase
  • Breakage 1: concept and requires are keywords now
  • Breakage 2: u8 literals are char8t now

Edited November 18, 2026

The default moved

GCC 16.1 was released on April 30, 2026. The GCC 16 changes page states the change in one line: "C++20 by default: GCC 16 changes the default language version for C++ compilation from -std=gnu++17 to -std=gnu++20." The same page tells unpinned codebases what to do: "If your code relies on older versions of the C++ standard, you will need to either add -std= to your build flags, or port your code; see the porting notes."

The first run confirms the default on the machine used for every test in this guide. Three compilers, default flags, one program that prints __cplusplus:

Compiler Version __cplusplus under default flags
g++ 13.3.0 201703
g++-16 16.2.0 202002
clang++-18 18.1.3 201703

g++-16 also reports __cpp_lib_concepts=202207 under its defaults, and __cplusplus=201703 when given -std=c++17. So the change is real and specific: GCC 16 defaults to C++20, GCC 13 and Clang 18 still default to C++17. Nothing else in this guide depends on a newer compiler — the box's GCC is 16.2.0, the Ubuntu build of the GCC 16 series, and every result below names it.

The legacy mini-codebase

The test subject is one file with five C++17-era idioms: std::result_of, a base class of std::iterator, allocator::construct and destroy, a u8 literal assigned to const char*, and a variable named concept. It computes 42 + 0 + 3 + 6 and returns 0 when the sum is 51:

C++
// A small unpinned C++17-era codebase: result_of + std::iterator base +
// allocator::construct + u8 literal + `concept` identifier.
#include <type_traits>
#include <iterator>
#include <memory>
#include <cstring>

int compute() { return 42; }
using ComputeResult = typename std::result_of<decltype(&compute)()>::type;

struct LegacyIter : public std::iterator<std::input_iterator_tag, int> {
    int v = 0;
    int operator*() const { return v; }
};

int main() {
    int concept = 3;
    const char* label = u8"legacy";
    std::allocator<int> a;
    int* p = a.allocate(1);
    a.construct(p, compute());
    LegacyIter it;
    int r = *p + *it + concept + static_cast<int>(std::strlen(label));
    a.destroy(p);
    a.deallocate(p, 1);
    return r == 42 + 0 + 3 + 6 ? 0 : 1;
}

Under g++-16 with default flags, it does not compile. Under g++-16 -std=c++17 and under g++ 13.3.0 with default flags, it compiles and runs, exit code 0 — which means the sum is 51, as written.

Output
== t10 [g16default]: COMPILE FAIL rc=1
    error lines (grep -c 'error:'): 6
== t10 [g16cxx17]: compile rc=0, run rc=0 (0 means sum==51)
== t10 [g13default]: compile rc=0, run rc=0 (0 means sum==51)

The full error output under the GCC 16 default, verbatim:

Output
t10_legacy.cpp:11:33: warning: ‘template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> struct std::iterator’ is deprecated [-Wdeprecated-declarations]
   11 | struct LegacyIter : public std::iterator<std::input_iterator_tag, int> {
      |                                 ^~~~~~~~
In file included from /home/user/gcc16/usr/include/c++/16/iterator:63,
                 from t10_legacy.cpp:4:
/home/user/gcc16/usr/include/c++/16/bits/stl_iterator_base_types.h:129:34: note: declared here
  129 |     struct _GLIBCXX17_DEPRECATED iterator
      |                                  ^~~~~~~~
t10_legacy.cpp: In function ‘int main()’:
t10_legacy.cpp:17:9: error: C++20 concept definition syntax is ‘concept <name> = <expr>’
   17 |     int concept = 3;
      |         ^~~~~~~
t10_legacy.cpp:17:17: error: expected unqualified-id before ‘=’ token
   17 |     int concept = 3;
      |                 ^
t10_legacy.cpp:18:25: error: invalid conversion from ‘const char8_t*’ to ‘const char*’ [-fpermissive]
   18 |     const char* label = u8"legacy";
      |                         ^~~~~~~~~~
      |                         |
      |                         const char8_t*
t10_legacy.cpp:21:7: error: ‘class std::allocator<int>’ has no member named ‘construct’
   21 |     a.construct(p, compute());
      |       ^~~~~~~~~
t10_legacy.cpp:23:24: error: expected primary-expression before ‘concept’
   23 |     int r = *p + *it + concept + static_cast<int>(std::strlen(label));
      |                        ^~~~~~~
t10_legacy.cpp:24:7: error: ‘class std::allocator<int>’ has no member named ‘destroy’
   24 |     a.destroy(p);
      |       ^~~~~~~

Count the errors carefully, because the count is the first thing a checklist gets wrong. The compiler prints 6 lines containing error:, for 5 distinct breakages. The sixth line — 17:17: error: expected unqualified-id before ‘=’ token — is the parser's knock-on from the concept declaration on the same line, not a separate problem. The five breakages are: concept used as an identifier (lines 17 and 23 are the same identifier breaking twice), the u8 conversion (line 18), construct (line 21), and destroy (line 24). The std::iterator line at the top is a warning, not an error — the file still fails, but not because of it. The next three sections take each hard breakage apart on its own, with the isolated test that proves it.

Breakage 1: concept and requires are keywords now

C++20 defines new keywords, and the Porting to GCC 16 guide says so directly: "C++20 defines new keywords such as concept and requires, which can no longer be used as identifiers." The isolated test is three lines:

C++
int main() {
    int concept = 1;
    int requires = 2;
    return concept + requires - 3;
}

Under g++-16 with default flags it fails with 7 error lines — the two bad identifiers cascade through the return statement. The first error is the one to read:

Output
t02_keywords.cpp:2:9: error: C++20 concept definition syntax is ‘concept <name> = <expr>’
    2 |     int concept = 1;
      |         ^~~~~~~
t02_keywords.cpp:2:17: error: expected unqualified-id before ‘=’ token
t02_keywords.cpp:3:9: error: expected unqualified-id before ‘requires’

Under -std=c++17, under GCC 13, and under Clang 18, the same file compiles and runs with exit code 0. The porting guide gives the only two fixes: "change the name of the identifier, or build to an older standard with (e.g.) -std=c++17." Renaming is the durable fix — a variable that cannot be named concept under the compiler your code will eventually build with is a rename waiting to happen. Pinning -std=c++17 buys time and nothing else.

Breakage 2: u8 literals are char8_t now

In C++20, u8"str" changed type from const char* to const char8_t*. The porting guide quotes the exact error this produces. The isolated test:

C++
int main() {
    const char* s = u8"hello";
    return s[0] == 'h' ? 0 : 1;
}
Output
t04_u8.cpp:2:21: error: invalid conversion from ‘const char8_t*’ to ‘const char*’ [-fpermissive]
    2 |     const char* s = u8"hello";
      |                     ^~~~~~~~~
      |                     |
      |                     const char8_t*

It fails only under the GCC 16 default. Under -std=c++17, GCC 13, and Clang 18 it compiles and runs — in C++17 a u8 literal is still const char*, so the assignment is legal there. The porting guide's fix is "a cast from the u8 literal to plain char or char const*." The fixed codebase below takes the other honest route: keep the u8 literal, declare the variable const char8_t*, and cast at the single place the bytes are read as char. Either way the fix is local to the line that holds the literal — the type change does not spread.

Breakage 3: allocator::construct and destroy are gone

C++20 removed the deprecated member functions of std::allocator, because std::allocator_traits has provided better defaults since C++11. The porting guide lists the removed members: pointer, const_pointer, reference, const_reference, construct, destroy, rebind, is_always_equal, and max_size. The isolated test:

C++
#include <memory>
int main() {
    std::allocator<int> a;
    int* p = a.allocate(1);
    a.construct(p, 42);
    int v = *p;
    a.destroy(p);
    a.deallocate(p, 1);
    return v == 42 ? 0 : 1;
}
Output
t05_allocator.cpp:5:7: error: ‘class std::allocator<int>’ has no member named ‘construct’
    5 |     a.construct(p, 42);
      |       ^~~~~~~~~
t05_allocator.cpp:7:7: error: ‘class std::allocator<int>’ has no member named ‘destroy’
    7 |     a.destroy(p);
      |       ^~~~~~~

It fails only under the GCC 16 default and passes under -std=c++17, GCC 13, and Clang 18. The porting guide's fix is the replacement spelling: "use (e.g.) std::allocator_traits<A>::destroy in place of A::destroy." The fixed codebase below applies exactly that, for both construct and destroy. Note that allocate and deallocate are untouched — they were never removed, and the fixed code keeps calling them as members.

Not a breakage: != is now generated from ==

This one is a behavior change, not a breakage, and it cuts in the direction most people do not expect: code that failed before now passes. In C++20, a type that defines operator== gets an operator!= provided implicitly by the compiler. The test is a struct with == only:

C++
#include <iostream>
struct Widget {
    int id;
    bool operator==(const Widget& o) const { return id == o.id; }
};
int main() {
    Widget a{1}, b{2};
    std::cout << (a != b) << "\n";
    return 0;
}
Compiler / flags Result
g++-16 default (C++20) rc=0, prints 1
g++-16 -std=c++17 FAIL: error: no match for ‘operator!=’ (operand types are ‘Widget’ and ‘Widget’)
g++ 13 default (C++17) FAIL: same no match for ‘operator!=’ error
clang++-18 default (C++17) FAIL: error: invalid operands to binary expression ('Widget' and 'Widget')

The C++20 build prints 1 because a and b differ, and the rewritten != negates ==. The migration risk the porting guide warns about is the reverse case: a type that defines its own operator!= with an unconventional signature can now become ambiguous against the compiler-generated one, with errors like error: ambiguous overload for 'operator!='. If a type must keep working on a pre-C++20 compiler, the portable spelling is an explicit operator!=, which was verified on both modes:

C++
bool operator!=(const Widget& o) const { return !(*this == o); }

With that line added, the test prints 1 under the GCC 16 default and under -std=c++17 alike. Reviewing overloads for that ambiguity is the actual work here — not adding != definitions everywhere, since C++20 already supplies them.

Three things that are not breakages on this toolchain

A checklist written from the standard alone would list three more removals. All three are wrong for GCC 16 with libstdc++ 16, and each one was run to prove it.

std::result_of is not removed. The standard removed it in C++20 — cppreference lists it as "(since C++11) (deprecated in C++17) (removed in C++20)", with std::invoke_result as the replacement. But libstdc++ 16 still defines it. The test compiles under the GCC 16 default, under -std=c++17, under GCC 13, and under Clang 18 — rc=0 on all four, zero warnings. The header is the reason: type_traits in the GCC 16 tree still defines result_of at lines 2727–2742, a SFINAE-friendly implementation with no __cplusplus upper-bound guard. The porting guide anticipates exactly this: "names removed from C++20 may still appear in headers when building under -std=c++20, and only provoke 'deprecated' warnings." So do not list result_of as a breakage for GCC 16 users — list it as a portability trap in the other direction. Code that relies on it still builds here and breaks on a conforming library. Migrate it to std::invoke_result anyway; the fixed codebase below does.

std::iterator is not removed either. Deriving from it compiles under the GCC 16 default on all four compilers in the matrix — rc=0 everywhere, with exactly 1 warning line each: warning: ‘template<...> struct std::iterator’ is deprecated [-Wdeprecated-declarations], pointing at stl_iterator_base_types.h:129, where the struct is declared struct _GLIBCXX17_DEPRECATED iterator. Deprecated, not removed. Teach it as "deprecated, still builds, fix it anyway" — never as a hard break. The fix is the five typedefs the base used to supply: iterator_category, value_type, difference_type, pointer, reference. The fixed codebase below writes them out directly.

Volatile compound assignment is a non-issue. v += 1 on a volatile int compiles under the GCC 16 default with -Wall -Wextra, rc=0, zero warning lines, and a 0-byte stderr file. The same holds under -std=c++17. Do not teach it as a C++20 breakage for GCC 16 users.

The corrected tally for the mini-codebase is therefore: of its 5 idioms, 3 break (the keyword, the u8 literal, the allocator members) and 2 compile with at most a warning (result_of, std::iterator). The != case is not one of the five idioms — it is a separate isolated test, and it changes behavior rather than breaking. The volatile case was never in the file at all — it was checked separately and cleared.

Diagnostics: JSON is gone, SARIF is the replacement

GCC 16 removed the JSON diagnostics format. The GCC 16 changes page lists it under caveats: "The so-called 'json' format for -fdiagnostics-format= has been removed in this release. Users seeking machine-readable diagnostics from GCC should use SARIF." The runs confirm it, using a one-line file with an undefined symbol:

Output
g++-16 -fdiagnostics-format=json: rc=1
    g++-16: error: unrecognized argument in option ‘-fdiagnostics-format=json’
    g++-16: note: valid arguments to ‘-fdiagnostics-format=’ are: sarif-file sarif-stderr text
g++-16 -fdiagnostics-format=sarif: rc=1
    g++-16: error: unrecognized argument in option ‘-fdiagnostics-format=sarif’
    g++-16: note: valid arguments to ‘-fdiagnostics-format=’ are: sarif-file sarif-stderr text

Two things to take from that rejection. First, the flag name is not sarif — bare sarif is rejected the same way json is. Second, GCC 13 still accepts json and emits JSON diagnostics, so a parser that worked on GCC 13 breaks the day the compiler moves to 16, with no deprecation period in between.

The two SARIF spellings both work. -fdiagnostics-format=sarif-stderr writes SARIF 2.1.0 JSON to stderr — the output starts with the SARIF 2.1.0 schema header and a runs array whose tool driver is named GNU C++20 — 4,520 bytes for the one-line bad file, and it parses as JSON. -fdiagnostics-format=sarif-file also works, and writes a file: with output work/t09-sarif-file and source t09_bad.cpp, the file appears as work/t09-sarif-file-t09_bad.cpp.sarif — 4,516 bytes, valid SARIF 2.1.0, tool GNU C++20, one result reporting ‘undefined_symbol’ was not declared in this scope. The naming rule is <output>-<source>.sarif in the output's directory, and stderr is empty (0 bytes) in that mode. That file output is worth stating plainly because an earlier probe of this same question reported no file: the earlier run looked for *.sarif in the probe directory, while the file lands next to the output binary, in work/. The flag was never broken; the search was looking in the wrong place. -fdiagnostics-format=text still works as before and is the third valid argument.

The fixed codebase

The same five idioms, fixed for the GCC 16 default. The changes are the ones the sections above already proved: result_of becomes invoke_result, the std::iterator base becomes five typedefs, concept becomes concept_id, the u8 literal becomes a const char8_t* with the cast at the single read site, and construct/destroy become std::allocator_traits calls:

C++
// The t10 legacy mini-codebase, fixed for g++-16 default (C++20).
// Same computation as t10_legacy.cpp: 42 + 0 + 3 + 6 = 51, return 0.
#include <type_traits>
#include <iterator>
#include <memory>
#include <cstring>

int compute() { return 42; }
using ComputeResult = typename std::invoke_result<decltype(&compute)>::type;

struct LegacyIter {
    using iterator_category = std::input_iterator_tag;
    using value_type = int;
    using difference_type = std::ptrdiff_t;
    using pointer = int*;
    using reference = int&;
    int v = 0;
    int& operator*() { return v; }
};

int main() {
    int concept_id = 3;
    const char8_t* label = u8"legacy";
    std::allocator<int> a;
    int* p = a.allocate(1);
    std::allocator_traits<std::allocator<int>>::construct(a, p, compute());
    LegacyIter it;
    int r = *p + *it + concept_id
        + static_cast<int>(std::strlen(reinterpret_cast<const char*>(label)));
    std::allocator_traits<std::allocator<int>>::destroy(a, p);
    a.deallocate(p, 1);
    return r == 42 + 0 + 3 + 6 ? 0 : 1;
}
Build Result
g++-16 default (C++20) compile rc=0, run rc=0 (sum 51), empty stderr
g++ 13 default (C++17) compile FAIL: error: ‘char8_t’ does not name a type; did you mean ‘wchar_t’?
C++17 variant (plain "legacy" literal, no char8_t) under g++-16 -std=c++17 compile rc=0, run rc=0 (sum 51)
C++17 variant under g++ 13 default compile rc=0, run rc=0 (sum 51)

The char8_t line is what makes the C++20 fixed version C++20-only: GCC 13 in C++17 mode has no char8_t type at all. That is the one place where the fix has to differ by standard. The C++17 variant changes exactly one line — the u8 literal becomes a plain literal — and then the same code builds and runs on all three compilers in the matrix. Everything else in the fix uses the same spelling on both standards: invoke_result, the five iterator typedefs, the renamed identifier, and allocator_traits.

The checklist

Seven items, in the order that gets a codebase building again:

  1. Pin the standard. -std=gnu++20 to adopt, -std=gnu++17 for continuity — never depend on the default, because the default is what moved.
  2. Rename concept and requires identifiers. Hard error, verbatim in the section above.
  3. Fix u8"..." to const char* conversions. Either keep the literal as const char8_t* and cast at the read site, or drop the u8 prefix — but note the char8_t spelling is C++20-only.
  4. Replace allocator::construct and destroy with std::allocator_traits<A>::construct and destroy. Same for the other removed members the porting guide lists.
  5. Review operator!= overloads. != is now generated from ==; check for the ambiguity the porting guide warns about, and add an explicit != only where a type must keep building pre-C++20.
  6. Migrate JSON diagnostics parsers to SARIF via -fdiagnostics-format=sarif-stderr (or sarif-file, which writes <output>-<source>.sarif). json and bare sarif are both rejected.
  7. Do not claim result_of, std::iterator, or volatile compound assignment as breakages on GCC 16 / libstdc++ 16. Migrate result_of to invoke_result and the iterator base to typedefs anyway — they still build here and will not build everywhere.

Frequently asked questions

My code compiled on GCC 13. What changed?

The default standard. GCC 13 defaults to gnu++17; GCC 16 defaults to gnu++20. Your code did not change and the compiler did not get stricter in some general sense. The language version it assumes when you do not say one moved by three years. Pin -std= and the question goes away until you are ready to port.

Is std::result_of really still there?

On this toolchain, yes. It compiles under the GCC 16.2.0 default with no warning. The standard removed it in C++20 and libstdc++ 16 kept it anyway. The header still defines it with no standard-version guard. That is a property of this library, not of the language. Do not write new code against it, and do not assume another C++20 library will have it.

Why does the mini-codebase report 6 errors for 5 breakages?

Because the concept declaration produces two error lines: the syntax error and the parser's knock-on expected unqualified-id before ‘=’ token on the same line. The concept identifier then breaks a second time where it is used. An error line is not a breakage: a migration report should say which one it is counting.

Can I keep the JSON diagnostics format?

No. GCC 16 removed it; the compiler rejects the flag and lists the valid arguments. The replacement is SARIF, through sarif-stderr for a stream or sarif-file for a file named <output>-<source>.sarif. GCC 13 still emits JSON, so a build that has to span both versions needs to select the format by compiler version.

Does any of this apply to Clang?

Not through the default. Clang 18 still defaults to C++17, so none of these breakages fire under its default flags. The matrix above shows every isolated test passing under clang++-18 defaults except the != test, which fails there for the opposite reason (C++17 has no generated !=). Clang's own C++20 mode is a separate question this guide does not test. One Clang-only corner is worked end to end in std::formatter That Compiles: A Clang-Only Specialization Project: a custom std::formatter specialization and a delegating formatter for a point type, built under Clang 18.

What is still untested after this guide?

The C++20 ABI changes the GCC 16 changes page lists: atomic wait/notify functions, <syncstream>, std::format argument representation, the std::variant ABI macro _GLIBCXX_USE_VARIANT_CXX17_OLD_ABI, which were read, not run, and are not presented as measured here. std::start_lifetime_as was not probed either. The guide's claims cover exactly the matrix above: GCC 16.2.0, GCC 13.3.0, and Clang 18.1.3 on Linux x86_64.

Source

  • GCC 16 Release Series — Changes, New Features, and Fixes: GCC 16 changes the default C++ standard from -std=gnu++17 to -std=gnu++20; the json format for -fdiagnostics-format= was removed and users seeking machine-readable diagnostics should use SARIF; C++20 library support is no longer experimental; the C++20 ABI changes (atomic wait/notify, <syncstream>, std::format args, std::variant) are listed.
  • GCC 16.1 Released: GCC 16.1 announced April 30, 2026; "The C++ frontend now defaults to the GNU C++20 dialect and the corresponding parts of the standard library are no longer experimental"; diagnostics can now be output in SARIF with enhanced control-flow features.
  • Porting to GCC 16: C++20 keywords concept and requires can no longer be used as identifiers (fix: rename, or build with -std=c++17); u8"str" literals changed from char to char8_t (fix: cast to plain char); operator!= is generated from operator== and can cause ambiguities; std::allocator members construct, destroy, rebind, and others were removed in favor of std::allocator_traits; names removed from C++20 may still appear in headers under -std=c++20 and only provoke deprecated warnings.
  • The GNU C++ Library Manual: the libstdc++ manual, including the C++ 2020 implementation-status table; the library-side reference for which C++20 components libstdc++ 16 provides.
  • std::result_of, std::invoke_result — cppreference: std::result_of is "(since C++11) (deprecated in C++17) (removed in C++20)"; std::invoke_result is the replacement since C++17.

Keep Exploring