Skip to content

Latest commit

 

History

History
913 lines (852 loc) · 12.9 KB

File metadata and controls

913 lines (852 loc) · 12.9 KB

variable

uninitialized

in

int a;

source

int a;

header

extern int a;

initialized with =

in

int a = 3;

source

int a = 3;

header

extern int a;

initialized with ()

in

int a(3);

source

int a(3);

header

extern int a;

multi

in

int a = 3, b, *c, d = 47;

source

int a = 3, b, *c, d=47;

header

extern int a, b, *c, d;

multiword type

in

long long int a = 1;

source

long long int a = 1;

header

extern long long int a;

array

in

int a[64];

source

int a[64];

header

extern int a[64];

array with automatic length

in

int a[] = {1, 2, 3};

source

int a[] = {1, 2, 3};

header

extern int a[3];

array with automatic length (complex)

in

struct X {int a, b; }; X a[] = {{1, 2}, {3, 4}, {5, 6}};

source

X a[] = {{1, 2}, {3, 4}, {5, 6}};

header

struct X; struct X {int a, b; }; extern X a[3];

array with automatic length (complex) (trailing comma)

in

struct X {int a, b; }; X a[] = {{1, 2}, {3, 4}, {5, 6}, };

source

X a[] = {{1, 2}, {3, 4}, {5, 6}, };

header

struct X; struct X {int a, b; }; extern X a[3];

typedef

simple

in

typedef int a;

header

typedef int a;

multi

in

typedef int a, *b;

header

typedef int a, *b;

unusual spelling

in

int typedef long a;

header

int typedef long a;

struct

simple

in

struct Thing { int a, b; char *c; };

header

struct Thing; struct Thing { int a, b; char *c; };

inheritance

in

struct Thing { int a, b; char *c; }; struct Thang: Thing { float d; };

header

struct Thing; struct Thang; struct Thing { int a, b; char *c; }; struct Thang: Thing { float d; };

typedef struct

simple

in

typedef struct b { int a; } b;

header

struct b; typedef struct b { int a; } b;

union

simple

in

union Thing { int a, b; char *c; };

header

union Thing; union Thing { int a, b; char *c; };

typedef union

simple

in

typedef union Thing { int a, b; char *c; } d;

header

union Thing; typedef union Thing { int a, b; char *c; } d;

enum

normal

in

enum MyEnum { a, b, c=3, d };

header

enum MyEnum { a, b, c=3, d };

anonymous

in

enum { a, b, c=3, d };

header

enum { a, b, c=3, d };

function

simple

dep

void stuff();

in

int fn(int a, char *b[]) { if (a || b[1]) { stuff(); } return b[2][0]; }

header

int fn(int a, char *b[]);

source

int fn(int a, char *b[]) { if (a || b[1]) { stuff(); } return b[2][0]; }

default arguments

in

int fn(int a=1) { return a; }

header

int fn(int a=1);

source

int fn(int a) { return a; }

namespace

simple

in

namespace ns { int a; void f() {} struct q { void m() {} }; }

header

namespace ns { extern int a; void f(); struct q; struct q { void m(); }; }

source

namespace ns { int a; void f() {} void q::m() {} }

reopened

in

namespace NS { struct S { void f() {} }; } namespace NS { struct T { void g() {} }; }

header

namespace NS { struct S; struct S { void f(); }; } namespace NS { struct T; struct T { void g(); }; }

source

namespace NS { void S::f() {} }

namespace NS { void T::g() {} }

nested

in

namespace ns { namespace ns1 { int a; void f() {} struct q { void m() {} }; } }

header

namespace ns { namespace ns1 { extern int a; void f(); struct q; struct q { void m(); }; } }

source

namespace ns { namespace ns1 { int a; void f() {} void q::m() {} } }

member function

simple

in

struct q { void f() {}};

header

struct q; struct q { void f(); };

source

void q::f() {}

const

in

struct q { void f() const {}};

header

struct q; struct q { void f() const; };

source

void q::f() const {}

rvalue this

in

struct q { void f() && {}};

header

struct q; struct q { void f() &&; };

source

void q::f() && {}

const rvalue this

in

struct q { void f() const && {}};

header

struct q; struct q { void f() const &&; };

source

void q::f() const && {}

static member var

single with init

in

struct S { static int a = 1; };

header

struct S; struct S { static int a; };

source

int S::a = 1;

multi with init

in

struct S { static int a=1, b=2; };

header

struct S; struct S { static int a, b; };

source

int S::a = 1, S::b = 2;

static const member var

single with init

in

struct S { static const int a = 1; };

header

struct S; struct S { static const int a; };

source

const int S::a = 1;

multi with init

in

struct S { static const int a=1, b=2; };

header

struct S; struct S { static const int a, b; };

source

const int S::a = 1, S::b = 2;

virtual function

simple

in

class C { virtual void f() = 0; }; class D: C { virtual void f() override {} };

header

class C; class D; class C { virtual void f() = 0; }; class D: C { virtual void f() override; };

source

void D::f() {}

template function

simple

in

template<class T, class U> T f(U a) { return a; }

header

template<class T, class U> T f(U a); template<class T, class U> T f(U a) { return a; }

template struct

simple

in

template<class T, class U> struct S { int q; int f() { return q; } };

header

template<class T, class U> struct S { int q; int f(); };

template<class T, class U> int S<T, U>::f() { return q; }

template member function

simple

in

struct q { template<class T, class U> T f(U a) { return a; } };

header

struct q; struct q { template<class T, class U> T f(U a); };

template<class T, class U> T q::f(U a) { return a; }

in template

in

template<class T> struct q { template<class R, class A> inline R f(A a) { return a; } };

header

template<class T> struct q { template<class R, class A> R f(A a) { return a; } };

class

simple

in

class C { public: int p; protected: int pp; private: int ppp; };

header

class C; class C { public: int p; protected: int pp; private: int ppp; };

inheritance

in

class C {}; class D: C {}; class E: public C {}; class F: protected C {}; class G: private C {}; class H: public D, protected E, private F {}; class I: public virtual C {};

header

class C; class D; class E; class F; class G; class H; class I; class C {}; class D: C {}; class E: public C {}; class F: protected C {}; class G: private C {}; class H: public D, protected E, private F {}; class I: public virtual C {};

enum class

simple

in

enum class E { a, b=1, c };

header

enum class E { a, b=1, c };

typed

in

enum class E: int { a, b=1, c };

header

enum class E: int { a, b=1, c };

typedef template

typedef before template

in

typedef S<int> Sint; template<class T> struct S {};

header

template<class T> struct S {}; typedef S<int> Sint;

template before typedef

in

template<class T> struct S {}; typedef S<int> Sint;

header

template<class T> struct S {}; typedef S<int> Sint;

lambda in ()-assignment

basic

dep

struct Thing { template<class T, class U> Thing(T t, U u) {} };

in

Thing myThing(“hi”, []() {});

header

extern Thing myThing;

source

Thing myThing(“hi”, []() {});

heavy

dep

struct Thing { template<class T, class U> Thing(T t, U u) {} }; void blah(const char *);

in

Thing myThing(“hi”, []() { blah(“poo”); });

header

extern Thing myThing;

source

Thing myThing(“hi”, []() { blah(“poo”); });

confusing

dep

struct Thing { template<class T, class U> Thing(T t, U u) {} }; void blah(const char *);

in

Thing myThing(“hi”, []() { blah(“))))”); int q = 4; });

header

extern Thing myThing;

source

Thing myThing(“hi”, []() { blah(“))))”); int q = 4; });

operators

assignment

in

struct S { S &operator=(const S &) { return *this; } };

header

struct S; struct S { S &operator=(const S &); };

source

S &S::operator=(const S &) { return *this; }

conversion

in

struct S { operator int() { return 4; } };

header

struct S; struct S { operator int(); };

source

S::operator int() { return 4; }

multiply (member)

in

struct S { int operator*(int i) { return 4; } };

header

struct S; struct S { int operator*(int i); };

source

int S::operator*(int i) { return 4; }

multiply (non-member)

in

struct S { };

int operator*(int i, S &s) { return 4; }

header

struct S; struct S { };

int operator*(int i, S &s);

source

int operator*(int i, S &s) { return 4; }

call

in

struct S { void operator()(const S &) {} };

header

struct S; struct S { void operator()(const S &); };

source

void S::operator()(const S &) {}

typedef dependencies

param

in

struct S {}; void f(T) {} typedef S T;

header

struct S; struct S {}; typedef S T; void f(T);

source

void f(T) {}

return

in

struct S {}; T f() { return T(); } typedef S T;

header

struct S; struct S {}; typedef S T; T f();

source

T f() { return T(); }

__declspec(property)

read-only

in

struct S { int getX() { return 42; } __declspec(property(get=getX)) int x; };

header

struct S; struct S { int getX(); __declspec(property(get=getX)) int x; };

source

int S::getX() { return 42; }

read-write

in

struct S { int getX() { return 42; } void setX(int x) {} __declspec(property(get=getX,put=setX)) int x; };

header

struct S; struct S { int getX(); void setX(int x); __declspec(property(get=getX, put=setX)) int x; };

source

int S::getX() { return 42; } void S::setX(int x) {}

__stdcall

basic

in

int __stdcall WindowProc() { return 0; }

header

int __stdcall WindowProc();

source

int __stdcall WindowProc() { return 0; }

member function

in

struct S { static int __stdcall WindowProc() { return 0; } };

header

struct S; struct S { static int __stdcall WindowProc(); };

source

int __stdcall S::WindowProc() { return 0; }

constexpr variable

simple

in

constexpr int x = 4;

header

constexpr int x = 4;

static member var

in

struct S { static constexpr int x = 4; };

header

struct S; struct S { static constexpr int x = 4; };

source

constexpr int S::x;

nonstatic member var

Not valid C++; we allow it as a shorthand for static.

in

struct S { constexpr int x = 4; };

header

struct S; struct S { static constexpr int x = 4; };

source

constexpr int S::x;

constexpr member function

simple

in

struct S { constexpr int f() { return 4; } };

header

struct S; struct S { constexpr int f(); }; constexpr int S::f() { return 4; }

extern “C”

variable

in

extern “C” int x;

header

extern “C” int x;

source

extern “C” int x;

function

in

extern “C” void f() {}

header

extern “C” void f();

source

extern “C” void f() {}

attribute

variable

in

MyAttr int x;

header

MyAttr extern int x;

source

MyAttr int x;

function

in

MyAttr void f() {}

header

MyAttr void f();

source

MyAttr void f() {}

struct

in

struct MyAttr s {};

header

struct s; struct MyAttr s {};

enum

in

MyAttr enum e {};

header

MyAttr enum e {};

enum class

in

MyAttr enum class e {};

header

MyAttr enum class e {};

bitfield

basic

in

struct S { int a; int b:1, c:2; int d; int e:3; };

header

struct S; struct S { int a; int b:1, c:2; int d; int e:3; };

silly

in

struct S { int (a): 1; };

header

struct S; struct S { int (a): 1; };

objc class

basic

in

@interface MyClass { int myvar; } @end

@implementation MyClass -(int)myInstanceMethod:(int)myArg { return myArg; } +(int)myClassMethod:(int)myArg { return myArg; } @end

header

@class MyClass; @interface MyClass { int myvar; } -(int)myInstanceMethod:(int)myArg; +(int)myClassMethod:(int)myArg; @end

source

@implementation MyClass -(int)myInstanceMethod:(int)myArg { return myArg; } +(int)myClassMethod:(int)myArg { return myArg; } @end

comments

single-line

in

int a = 1; // int b = 2; int c = 3; // int d1 = 4; // int d2 = 4; int e = 5;

header

extern int a; extern int c; extern int e;

source

int a = 1; int c = 3; int e = 5;

multi-line

in

int a = 1; * int b1 = 2; int b2 = 2; * int c = 3; /* int d0 = 4; int d1 = 4; int d2 = 4; */ int e = 5;

header

extern int a; extern int c; extern int e;

source

int a = 1; int c = 3; int e = 5;

directives

#pragma depends

in

#pragma depends Thing

header

source

#line

in

int a = 1; #line 50 “ZAG” int b = 2;

header

extern int a; extern int b;

source

int a = 1; int b = 2;

#

in

int a = 1;

int b = 2;

header

extern int a; extern int b;

source

int a = 1; int b = 2;

empty file

simple

in

header

source