Does G++ compile it?
With only a filename on the command line of
g++ (Gentoo 4.8.3 p1.1, pie-0.5.9) 4.8.3 Copyright (C) 2013 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 [-Wtrigraphs] char file_pattern[] = "all-??-of-20"; ^
-
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:0: warning: "c" redefined [enabled by default] #define c a ^ src/define_indirect.cc:2:0: note: this is the location of the previous definition #define c b ^
-
#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:13: error: multiple types in one declaration typedef int int; ^ src/int_typedef.cc:1:13: error: declaration does not declare anything [-fpermissive]
-
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:10: error: invalid conversion from ‘int (*)()’ to ‘int’ [-fpermissive] return i; ^
-
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 = 08; ^
-
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:24: error: lvalue required as increment operand int main() { int i; i++++; } ^
-
int main() { int i; ++i++; }
Nosrc/plus_prepost.cc: In function ‘int main()’: src/plus_prepost.cc:1:24: error: lvalue required as increment operand int main() { int i; ++i++; } ^
-
#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:23: error: no matching function for call to ‘max(int&, unsigned int&)’ return std::max(a, b); ^ src/max.cc:5:23: note: candidates are: In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4/algorithm:61:0, from src/max.cc:1: /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4/bits/stl_algobase.h:216:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&) max(const _Tp& __a, const _Tp& __b) ^ /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4/bits/stl_algobase.h:216:5: note: template argument deduction/substitution failed: src/max.cc:5:23: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘unsigned int’) return std::max(a, b); ^ In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4/algorithm:61:0, from src/max.cc:1: /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4/bits/stl_algobase.h:260:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare) max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4/bits/stl_algobase.h:260:5: note: template argument deduction/substitution failed: src/max.cc:5:23: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘unsigned int’) return std::max(a, b); ^
-
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>)’: src/template.cc:3:8: error: need ‘typename’ before ‘std::vector<T>::iterator’ because ‘std::vector<T>’ is a dependent scope for (std::vector<T>::iterator i = in.begin(); i != in.end(); ++i) {} ^ src/template.cc:3:33: error: expected ‘;’ before ‘i’ for (std::vector<T>::iterator i = in.begin(); i != in.end(); ++i) {} ^ src/template.cc:3:49: error: ‘i’ was not declared in this scope for (std::vector<T>::iterator i = in.begin(); i != in.end(); ++i) {} ^
-
template <class T> class A {
template <class U> class B {};
};
template <class V> void F() {
typedef A<V>::B<V> T;
}
int main() {}
Nosrc/template_nested1.cc: In function ‘void F()’: src/template_nested1.cc:5:17: error: non-template ‘B’ used as template typedef A<V>::B<V> T; ^ src/template_nested1.cc:5:17: note: use ‘A<V>::template B’ to indicate that it is a template src/template_nested1.cc:5:11: error: need ‘typename’ before ‘A<V>::B’ because ‘A<V>’ is a dependent scope typedef A<V>::B<V> T; ^
-
template <class T> class A {
template <class U> class B {};
};
template <class V> void F() {
typedef A<V>::template B<V> T;
}
int main() {}
Nosrc/template_nested2.cc: In function ‘void F()’: src/template_nested2.cc:5:11: error: need ‘typename’ before ‘A<V>::B<V>’ because ‘A<V>’ is a dependent scope typedef A<V>::template B<V> T; ^
-
template <class T> class A {
template <class U> class B {};
};
template <class V> void F() {
typedef typename A<V>::template B<V> T;
}
int main() {}
Yes -
template <class T> class A {
template <class U> class B {};
};
template <class V> void F() {
typedef typename A<V>::template B<V> T;
}
int main() {
F<int>();
}
Nosrc/template_nested4.cc: In instantiation of ‘void F() [with V = int]’: src/template_nested4.cc:8:10: required from here src/template_nested4.cc:2:28: error: ‘template<class U> class A<int>::B’ is private template <class U> class B {}; ^ src/template_nested4.cc:5:40: error: within this context typedef typename A<V>::template B<V> T; ^
-
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:26: error: no matching function for call to ‘OptimizedStrlen(const char [6])’ OptimizedStrlen("value"); ^ src/template_array.cc:5:26: note: candidate is: src/template_array.cc:1:35: note: template<unsigned int size> unsigned int OptimizedStrlen(const char*) template <unsigned size> unsigned OptimizedStrlen(const char value[size]) { ^ src/template_array.cc:1:35: note: template argument deduction/substitution failed: src/template_array.cc:5:26: note: couldn't deduce template parameter ‘size’ OptimizedStrlen("value"); ^
-
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:12: error: expected primary-expression before ‘>’ token A<T>::f<T>(); ^ src/template_member.cc:5:14: error: expected primary-expression before ‘)’ token A<T>::f<T>(); ^
-
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:50: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11 template <class T = unsigned int> void DoNothing() {} ^
-
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:8: error: ‘void Foo::Bar()’ cannot be overloaded void Bar() {} ^ src/virtual2.cc:2:16: error: with ‘virtual void Foo::Bar()’ virtual void Bar() = 0; ^
-
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:14: error: ‘<::’ cannot begin a template-argument list [-fpermissive] std::vector<::foo::Bar> baz; ^ src/digraph_namespace.cc:6:14: note: ‘<:’ is an alternate spelling for ‘[’. Insert whitespace between ‘<’ and ‘::’ src/digraph_namespace.cc:6:14: note: (if you use ‘-fpermissive’ or ‘-std=c++11’, or ‘-std=gnu++11’ G++ will accept your code)
-
int (*main)() = 0;
Yes -
int main() {
return ("foo", 1);
}
Yes -
int main() {
return compl 1;
}
Thanks to the contributors. Contact me (address at top) to contribute or if you actually want your name attached.