Consider the following program:
#include <iostream>
namespace N {
int j = 1;
}
namespace M {
typedef int N;
void f() {
std::cout << N::j << std::endl;
}
}
int main() { M::f(); }
Compiling it with clang gives the following compiler error:
prog.cc:10:22: error: 'N' (aka 'int') is not a class, namespace, or
enumeration
std::cout << N::j << std::endl;
^ 1 error generated.
GCC does not give any compiler error. I'm trying to figure out for what compiler I should file the bug report for. Which compiler has the correct behaviour and why (references to the c++ standard)?
Wandbox - Clang: http://melpon.org/wandbox/permlink/s0hKOxCFPgq5aSmJ
Wandbox - GCC: http://melpon.org/wandbox/permlink/i2kOl3qTBVUcJVbZ
GCC consistently outperformance Clang on all optimization levels. 32 Bit Performance is on a bit lower side with respect to corresponding 64-bit compilers & optimization levels. This can be attributed to being able to utilize the RAM properly. The contrast between O0 & Other optimization levels is very visible.
Sometimes a program is a lot faster when compiled with GCC, sometimes it's a lot faster with clang. Usually it's marginally faster with GCC. Clang attempts to unroll loops really, really aggressively. Even at -O2 : Clang's loop unrolling attempts at -O2 are more aggressive than GCC's loop unrolling attempts at -O3 .
GCC and C99 allow an array's size to be determined at run time. This extension is not permitted in standard C++. However, Clang supports such variable length arrays for compatibility with GNU C and C99 programs. If you would prefer not to use this extension, you can disable it with -Werror=vla.
While LLVM's Clang C/C++ compiler was traditionally known for its faster build speeds than GCC, in recent releases of GCC the build speeds have improved and in some areas LLVM/Clang has slowed down with further optimization passes and other work added to its growing code-base.
Clang is correct on this one. Quoting C++11, 3.4.3/1 [basic.lookup.qual]:
... If a
::
scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that::
considers only namespaces, types, and templates whose specializations are types. If the name found does not designate a namespace or a class, enumeration, or dependent type, the program is ill-formed.
Per this clause, types are supposed to be considered during the lookup, so the typedef N
should be found. And since it does not designate a namespace, class, enumeration, or dependent type, the program is ill-formed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With