Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neither clang nor g++ compile the snippet below. Why? [duplicate]

Tags:

People also ask

Can Clang compile itself?

Clang C++ can parse GCC 4.2 libstdc++ and generate working code for non-trivial programs, and can compile itself.

Does Clang define __ GNUC __?

(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.

What does Clang mean in C++?

The Clang tool is a front end compiler that is used to compile programming languages such as C++, C, Objective C++ and Objective C into machine code. Clang is also used as a compiler for frameworks like OpenMP, OpenCL, RenderScript, CUDA and HIP.

What is Clang vs GCC?

Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools.


From [class.access]/7 we have the following sentence:

Similarly, the use of A::B as a base-specifier is well-formed because D is derived from A, so checking of base-specifiers must be deferred until the entire base-specifier-list has been seen.

class A {
protected:
    struct B { };
};
struct D: A::B, A { };

See live example with clang. As a matter of fact, clang also complains about this snippet, where no deferment is necessary.

class A {
protected:
    struct B { };
};
struct D: A, A::B { };

Why does this code not compile?

PS: gcc and VS21013 don't compile the codes either.