# Amazing feats of Clang Error Recovery

DevFeed: [Amazing feats of Clang Error Recovery](<https://devfeed.tech/articles/amazing-feats-of-clang-error-recovery-42845.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html>)

Author: Chris Lattner

Published: 2010-04-05T23:20:00Z

Content type: article

Language: en

Sources: [The LLVM Project Blog](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [clang](<https://devfeed.tech/topics/clang.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Parsing](<https://devfeed.tech/topics/parsing.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [C](<https://devfeed.tech/topics/c.md>), [bug](<https://devfeed.tech/topics/bug.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [diagnostics](<https://devfeed.tech/tags/diagnostics.md>), [error](<https://devfeed.tech/tags/error.md>), [parsing](<https://devfeed.tech/tags/parsing.md>)

## AI overview

A technical article explains how Clang's compiler frontend handles invalid C and C++ code, produces diagnostics, and recovers from parsing ambiguities such as unknown typenames and missing header files. It contrasts some examples with older GCC behavior.

## Source excerpt

In addition to parsing and generating machine code for your source files when valid, a compiler frontend's job is also to detect invalid code and give you a hint that explains what is wrong so you can fix the problem. The bug could either be straight-up invalid (an error) or could just be something that is legal but looks really dubious (a warning). These errors and warnings are known as compiler 'diagnostics', and Clang aims to go above and beyond the call of duty to provide a really amazing experience. After the break, we show some examples of areas where Clang tries particularly hard. For other examples, the Clang web page also has a page on diagnostics and Doug showed how Clang diagnoses two-phase name lookup issues in a prior blog post. Update: Other people are starting to compare their favorite compiler. Here's the OpenVMS Compiler. Email Chris if you have a comparison you want posted. Секреты восстановления (Russian Translation) provided by Softdroid Recovery. Ukrainian Translation provided by Sandi Wolfe. Estonian Translation provided by Johanne Teerink. German Translation provided by Philip Egger. Spanish Translation provided by Laura Mancini These examples use Apple GCC 4.2 as a comparison on these examples, but this isn't meant to bash (an old version of) GCC. Many compilers have these sorts of issues and we strongly encourage you to try the examples on your favorite compiler to see how it does. The examples all shown are necessarily small (reduced) examples that demonstrate a problem, when you see these in real life, they are often much more convincing :). Unknown Typenames One annoying thing about parsing C and C++ is that you have to know what is a typename in order to parse the code. For example "(x)(y)" can be either a cast of the expression "(y)" to type "x" or it could be a call of the "x" function with the "(y)" argument list, depending on whether x is a type or not. Unfortunately, a common mistake is to forget to include a header file, which mean