Does G++ compile it?
With only a filename on the command line of
g++ (Gentoo 4.3.4 p1.0, pie-10.1.5) 4.3.4 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
int main() {
<%"\?"<:0:>;%>
}
Yes Once the C99 digraphs are simplified, the line reads{"\?"[0];}which is equivalent to simply '?';. -
int main() {
char file_pattern[] = "all-??-of-20";
}
Yes ??- is a C trigraph which, by default, is treated as normal text with a warning.src/trigraph.cc:2:30: warning: trigraph ??- ignored, use -trigraphs to enable
-
int main() {
int x,y=x?:y;
}
Yes A GCC extension allows omitting the middle operand of a conditional. If the condition is true, the condition is returned. -
#define assert(a) FOO
#include <assert.h>
#undef assert
#include <assert.h>
int main() {
assert(0);
}
Yes ISO C99 Standard: 7.2 Diagnostics specifies that assert is redefined every time assert.h is included. Mostly this is to allow defining NDEBUG after the first inclusion of assert.h. -
#define foo bar
#define foo bar
int main() {}
Yes -
#define b a
#define c b
#define c a
int main() {}
Yessrc/define_indirect.cc:3:1: warning: "c" redefined src/define_indirect.cc:2:1: warning: this is the location of the previous definition
-
#define a b
#define b a
int main() {
int a, b;
}
Yes -
class Bar {};
Bar Bar();
int main() {}
Yes -
class Bar {};
Bar Bar;
int main() {}
Yes -
class Bar {};
typedef Bar Bar;
int main() {}
Yes -
typedef int int;
int main() {}
Nosrc/int_typedef.cc:1: error: multiple types in one declaration src/int_typedef.cc:1: error: declaration does not declare anything
-
int main() {
int i();
return i;
}
No For C compatibility, i is interpreted as a function declaration.src/int_init.cc: In function ‘int main()’: src/int_init.cc:3: error: invalid conversion from ‘int (*)()’ to ‘int’
-
int i = 08;
int main() {}
No A leading 0 introduces an octal number. 8 is not octal.src/int_number.cc:1:9: error: invalid digit "8" in octal constant
-
int i = i;
int main() {}
Yes -
int main() {
int i, j;
(+ +i+++ + ++++j);
}
Yes Read as +(+(i++)) + +(++++j). The pluses before i are unary + and do nothing. The the third + after i is actually binary addition. -
int main() { int i; i++++; }
Nosrc/plus_post2.cc: In function ‘int main()’: src/plus_post2.cc:1: error: lvalue required as increment operand
-
int main() { int i; ++i++; }
Nosrc/plus_prepost.cc: In function ‘int main()’: src/plus_prepost.cc:1: error: lvalue required as increment operand
-
#include <algorithm>
int main() {
int a;
unsigned int b = 0;
return std::max(a, b);
}
No Typical type matching requirement of C++. Use std::max<int> instead.src/max.cc: In function ‘int main()’: src/max.cc:5: error: no matching function for call to ‘max(int&, unsigned int&)’
-
int main() {
return main();
}
Yes -
#include <vector>
template <class T> void Foo(std::vector<T> in) {
for (std::vector<T>::iterator i = in.begin(); i != in.end(); ++i) {}
}
int main() {}
No The compiler can't tell that std::vector<T>::iterator is a type. Fix with typename std::vector<T>::iterator.src/template.cc: In function ‘void Foo(std::vector<T, std::allocator<_Tp1> >)’: src/template.cc:3: error: expected `;' before ‘i’ src/template.cc:3: error: ‘i’ was not declared in this scope
-
template <unsigned size> unsigned OptimizedStrlen(const char value[size]) {
return size;
}
int main() {
OptimizedStrlen("value");
}
Nosrc/template_array.cc: In function ‘int main()’: src/template_array.cc:5: error: no matching function for call to ‘OptimizedStrlen(const char [6])’
-
template <unsigned size> unsigned OptimizedStrlen(const char (&value)[size]) {
return size;
}
int main() {
OptimizedStrlen("value");
}
Yes discussion -
template <class S> struct A {
template <class T> static void f() {}
};
template <class T> void g() {
A<T>::f<T>();
}
int main() {}
Nosrc/template_member.cc: In function ‘void g()’: src/template_member.cc:5: error: expected primary-expression before ‘>’ token src/template_member.cc:5: error: expected primary-expression before ‘)’ token
-
template <class S> struct A {
template <class T> static void f() {}
};
template <class T> void g() {
A<T>::template f<T>();
}
int main() {}
Yes -
template <class T = unsigned int> void DoNothing() {}
int main() {}
Nosrc/template_function.cc:1: error: default template arguments may not be used in function templates
-
int main() {
int a[3];
2[a];
}
Yes foo[bar] is equivalent to *(foo + bar). -
class Foo {
virtual void Bar() = 0;
};
void Foo::Bar() {}
int main() {}
Yes -
class Foo {
virtual void Bar() = 0;
void Bar() {}
};
int main() {}
Nosrc/virtual2.cc:3: error: ‘void Foo::Bar()’ cannot be overloaded src/virtual2.cc:2: error: with ‘virtual void Foo::Bar()’
-
int main() {
char a;
switch(a) {
case 0 ... 2:
break;
}
}
Yes Extension -
int main() {
(1, "foo");
}
Yes -
#include <vector>
namespace foo {
struct Bar {};
}
int main() {
std::vector<::foo::Bar> baz;
}
Nosrc/digraph_namespace.cc: In function ‘int main()’: src/digraph_namespace.cc:6: error: ‘<::’ cannot begin a template-argument list src/digraph_namespace.cc:6: note: ‘<:’ is an alternate spelling for ‘[’. Insert whitespace between ‘<’ and ‘::’ src/digraph_namespace.cc:6: note: (if you use -fpermissive G++ will accept your code)
Thanks to the contributors. E-mail <compile at kheafield.com> to contribute or if you actually want your name attached.