/eclipse-cdt-8.1.0/org.eclipse.cdt-CDT_8_1_0/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java
Java | 6973 lines | 1768 code | 514 blank | 4691 comment | 0 complexity | fa79a34464d428c6ea5b17a0216b68cd MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Devin Steffler (IBM Corporation) - initial API and implementation
- * Markus Schorn (Wind River Systems)
- *******************************************************************************/
- package org.eclipse.cdt.core.parser.tests.ast2;
- import junit.framework.TestSuite;
- import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
- import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
- import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
- import org.eclipse.cdt.core.dom.ast.IASTExpression;
- import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
- import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
- import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
- import org.eclipse.cdt.core.dom.ast.IASTName;
- import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
- import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
- import org.eclipse.cdt.core.dom.ast.IASTTypeId;
- import org.eclipse.cdt.core.dom.ast.IBasicType;
- import org.eclipse.cdt.core.dom.ast.IBinding;
- import org.eclipse.cdt.core.dom.ast.IFunction;
- import org.eclipse.cdt.core.dom.ast.IProblemBinding;
- import org.eclipse.cdt.core.dom.ast.IType;
- import org.eclipse.cdt.core.dom.ast.ITypedef;
- import org.eclipse.cdt.core.dom.ast.IVariable;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
- import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
- import org.eclipse.cdt.core.parser.ParserLanguage;
- import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
- import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
- /**
- * Examples taken from the c++-specification.
- */
- public class AST2CPPSpecTest extends AST2SpecBaseTest {
- public AST2CPPSpecTest() {
- }
- public AST2CPPSpecTest(String name) {
- super(name);
- }
- public static TestSuite suite() {
- return suite(AST2CPPSpecTest.class);
- }
- // int x=x+++++y;
- public void test2_4s5() throws Exception {
- parseCandCPP(getAboveComment(), false, 0);
- }
- // int a=12, b=014, c=0XC;
- public void test2_13_1s1() throws Exception {
- parseCandCPP(getAboveComment(), true, 0);
- }
- // ??=define arraycheck(a,b) a??(b??) ??!??! b??(a??)
- // // becomes
- // #define arraycheck(a,b) a[b] || b[a]
- public void test2_3s2() throws Exception { // TODO exists bug 64993
- parseCandCPP(getAboveComment(), true, 0);
- }
- // int a; // defines a
- // extern const int c = 1; // defines c
- // int f(int x) { return x+a; } // defines f and defines x
- // struct S { int a; int b; }; // defines S, S::a, and S::b
- // struct X { // defines X
- // int x; // defines nonstatic data member x
- // static int y; // declares static data member y
- // X(): x(0) { } // defines a constructor of X
- // };
- // int X::y = 1; // defines X::y
- // enum { up, down }; // defines up and down
- // namespace N { int d; } // defines N and N::d
- // namespace N1 = N; // defines N1
- // X anX; // defines anX
- // // whereas these are just declarations:
- // extern int a; // declares a
- // extern const int c; // declares c
- // int f(int); // declares f
- // struct S; // declares S
- // typedef int Int; // declares Int
- // extern X anotherX; // declares anotherX
- // using N::d; // declares N::d
- public void test3_1s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct C {
- // string s; // string is the standard library class (clause 21)
- // };
- // int main()
- // {
- // C a;
- // C b = a;
- // b = a;
- // }
- public void test3_1s4a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // struct C {
- // string s;
- // C(): s() { }
- // C(const C& x): s(x.s) { }
- // C& operator=(const C& x) { s = x.s; return *this; }
- // ~C() { }
- // };
- //
- public void test3_1s4b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // struct X; // declare X as a struct type
- // struct X* x1; // use X in pointer formation
- // X* x2; // use X in pointer formation
- public void test3_2s4() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // // translation unit 1:
- // struct X {
- // X(int);
- // X(int, int);
- // };
- // X::X(int = 0) { }
- // class D: public X { };
- // D d2; // X(int) called by D()
- public void test3_2s5_a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // // translation unit 2:
- // struct X {
- // X(int);
- // X(int, int);
- // };
- // X::X(int = 0, int = 0) { }
- // class D: public X { }; // X(int, int) called by D();
- // // D()'s implicit definition
- // // violates the ODR
- public void test3_2s5_b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int j = 24;
- // int main()
- // {
- // int i = j, j;
- // j = 42;
- // }
- public void test3_3s2() throws Exception {
- parseCandCPP(getAboveComment(), true, 0);
- }
- // int foo() {
- // int x = 12;
- // { int x = x; }
- // }
- public void test3_3_1s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // const int i = 2;
- // { int i[i]; }
- // }
- public void test3_3_1s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // const int x = 12;
- // { enum { x = x }; }
- // }
- public void test3_3_1s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace N {
- // int i;
- // int g(int a) { return a; }
- // int j();
- // void q();
- // }
- // namespace { int l=1; }
- // // the potential scope of l is from its point of declaration
- // // to the end of the translation unit
- // namespace N {
- // int g(char a) // overloads N::g(int)
- // {
- // return l+a; // l is from unnamed namespace
- // }
- // int i; // error: duplicate definition
- // int j(); // OK: duplicate function declaration
- // int j() // OK: definition of N::j()
- // {
- // return g(i); // calls N::g(int)
- // }
- // int q(); // error: different return type
- // }
- public void test3_3_5s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // namespace N {
- // void f();
- // }
- // }
- // void A::N::f() {
- // int i = 5;
- // // The following scopes are searched for a declaration of i:
- // // 1) outermost block scope of A::N::f, before the use of i
- // // 2) scope of namespace N
- // // 3) scope of namespace A
- // // 4) global scope, before the definition of A::N::f
- // }
- public void test3_4_1s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace M {
- // class B { };
- // }
- public void test3_4_1s7() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class B { };
- // namespace M {
- // namespace N {
- // class X : public B {
- // void f();
- // };
- // }
- // }
- // void M::N::X::f() {
- // int i = 16;
- // }
- // // The following scopes are searched for a declaration of i:
- // // 1) outermost block scope of M::N::X::f, before the use of i
- // // 2) scope of class M::N::X
- // // 3) scope of M::N::X's base class B
- // // 4) scope of namespace M::N
- // // 5) scope of namespace M
- // // 6) global scope, before the definition of M::N::X::f
- public void test3_4_1s8() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct A {
- // typedef int AT;
- // void f1(AT);
- // void f2(float);
- // };
- // struct B {
- // typedef float BT;
- // friend void A::f1(AT); // parameter type is A::AT
- // friend void A::f2(BT); // parameter type is B::BT
- // };
- public void test3_4_1s10() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class A {
- // public:
- // static int n;
- // };
- // int main()
- // {
- // int A;
- // A::n = 42; // OK
- // A b; // illformed: A does not name a type
- // }
- public void test3_4_3s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 1);
- }
- // namespace NS {
- // class T { };
- // void f(T);
- // }
- // NS::T parm;
- // int main() {
- // f(parm); //OK: calls NS::f
- // }
- public void test3_4_2s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class X { };
- // class C {
- // class X { };
- // static const int number = 50;
- // static X arr[number];
- // };
- // X C::arr[number]; // illformed:
- // // equivalent to: ::X C::arr[C::number];
- // // not to: C::X C::arr[C::number];
- public void test3_4_3s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct C {
- // typedef int I;
- // };
- // typedef int I1, I2;
- // int foo() {
- // extern int* p;
- // extern int* q;
- // p->C::I::~I(); // I is looked up in the scope of C
- // q->I1::~I2(); // I2 is looked up in the scope of
- // };
- // // the postfixexpression
- // struct A {
- // ~A();
- // };
- // typedef A AB;
- // int main()
- // {
- // AB *p;
- // p->AB::~AB(); // explicitly calls the destructor for A
- // }
- public void test3_4_3s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // int x;
- // namespace Y {
- // void f(float);
- // void h(int);
- // }
- // namespace Z {
- // void h(double);
- // }
- // namespace A {
- // using namespace Y;
- // void f(int);
- // void g(int);
- // int i;
- // }
- // namespace B {
- // using namespace Z;
- // void f(char);
- // int i;
- // }
- // namespace AB {
- // using namespace A;
- // using namespace B;
- // void g();
- // }
- // void h()
- // {
- // AB::g(); // g is declared directly in AB,
- // // therefore S is { AB::g() } and AB::g() is chosen
- // AB::f(1); // f is not declared directly in AB so the rules are
- // // applied recursively to A and B;
- // // namespace Y is not searched and Y::f(float)
- // // is not considered;
- // // S is { A::f(int), B::f(char) } and overload
- // // resolution chooses A::f(int)
- // AB::f('c'); //as above but resolution chooses B::f(char)
- // AB::x++; // x is not declared directly in AB, and
- // // is not declared in A or B, so the rules are
- // // applied recursively to Y and Z,
- // // S is { } so the program is illformed
- // AB::i++; // i is not declared directly in AB so the rules are
- // // applied recursively to A and B,
- // // S is { A::i, B::i } so the use is ambiguous
- // // and the program is illformed
- // AB::h(16.8); // h is not declared directly in AB and
- // // not declared directly in A or B so the rules are
- // // applied recursively to Y and Z,
- // // S is { Y::h(int), Z::h(double) } and overload
- // // resolution chooses Z::h(double)
- // }
- public void test3_4_3_2s2() throws Exception {
- String[] problems= {"AB::x", "x", "AB::i", "i"};
- parse(getAboveComment(), ParserLanguage.CPP, problems); // qualified names are counted double, so 4
- }
- // namespace A {
- // int a;
- // }
- // namespace B {
- // using namespace A;
- // }
- // namespace C {
- // using namespace A;
- // }
- // namespace BC {
- // using namespace B;
- // using namespace C;
- // }
- // void f()
- // {
- // BC::a++; //OK: S is { A::a, A::a }
- // }
- // namespace D {
- // using A::a;
- // }
- // namespace BD {
- // using namespace B;
- // using namespace D;
- // }
- // void g()
- // {
- // BD::a++; //OK: S is { A::a, A::a }
- // }
- public void test3_4_3_2s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace B {
- // int b;
- // }
- // namespace A {
- // using namespace B;
- // int a;
- // }
- // namespace B {
- // using namespace A;
- // }
- // void f()
- // {
- // A::a++; //OK: a declared directly in A, S is { A::a }
- // B::a++; //OK: both A and B searched (once), S is { A::a }
- // A::b++; //OK: both A and B searched (once), S is { B::b }
- // B::b++; //OK: b declared directly in B, S is { B::b }
- // }
- public void test3_4_3_2s4() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // struct x { };
- // int x;
- // int y;
- // }
- // namespace B {
- // struct y {};
- // }
- // namespace C {
- // using namespace A;
- // using namespace B;
- // int i = C::x; // OK, A::x (of type int)
- // int j = C::y; // ambiguous, A::y or B::y
- // }
- public void test3_4_3_2s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // namespace B {
- // void f1(int);
- // }
- // using namespace B;
- // }
- // void A::f1(int) { } // illformed,
- // // f1 is not a member of A
- public void test3_4_3_2s6a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // namespace B {
- // void f1(int);
- // }
- // }
- // namespace C {
- // namespace D {
- // void f1(int);
- // }
- // }
- // using namespace A;
- // using namespace C::D;
- // void B::f1(int){} // OK, defines A::B::f1(int)
- public void test3_4_3_2s6b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct Node {
- // struct Node* Next; // OK: Refers to Node at global scope
- // struct Data* Data; // OK: Declares type Data
- // // at global scope and member Data
- // };
- // struct Data {
- // struct Node* Node; // OK: Refers to Node at global scope
- // friend struct ::Glob; // error: Glob is not declared
- // // cannot introduce a qualified type (7.1.5.3)
- // friend struct Glob; // OK: Refers to (as yet) undeclared Glob
- // // at global scope.
- //
- // };
- // struct Base {
- // struct Data; // OK: Declares nested Data
- // struct ::Data* thatData; // OK: Refers to ::Data
- // struct Base::Data* thisData; // OK: Refers to nested Data
- // friend class ::Data; // OK: global Data is a friend
- // friend class Data; // OK: nested Data is a friend
- // struct Data { //
- // }; // Defines nested Data
- // struct Data; // OK: Redeclares nested Data
- // };
- // struct Data; // OK: Redeclares Data at global scope
- // struct ::Data; // error: cannot introduce a qualified type (7.1.5.3)
- // struct Base::Data; // error: cannot introduce a qualified type (7.1.5.3)
- // struct Base::Datum; // error: Datum undefined
- // struct Base::Data* pBase; // OK: refers to nested Data
- public void test3_4_4s3() throws Exception {
- String[] problems= {"::Glob", "Glob", "Base::Datum", "Datum"};
- parse(getAboveComment(), ParserLanguage.CPP, problems);
- }
- // static void f();
- // static int i = 0; //1
- // void g() {
- // extern void f(); // internal linkage
- // int i; //2: i has no linkage
- // {
- // extern void f(); // internal linkage
- // extern int i; //3: external linkage
- // }
- // }
- public void test3_5s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace X {
- // void p()
- // {
- // q(); //error: q not yet declared
- // extern void q(); // q is a member of namespace X
- // }
- // void middle()
- // {
- // q(); //error: q not yet declared
- // }
- // void q() { //
- // } // definition of X::q
- // }
- // void q() { //
- // } // some other, unrelated q
- public void test3_5s7() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // void f()
- // {
- // struct A { int x; }; // no linkage
- // extern A a; // illformed
- // typedef A B;
- // extern B b; // illformed
- // }
- public void test3_5s8() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int main(int argc, char* argv[]) { //
- // }
- public void test3_6_1s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct B {
- // virtual void f();
- // void mutate();
- // virtual ~B();
- // };
- // struct D1 : B { void f(); };
- // struct D2 : B { void f(); };
- // void B::mutate() {
- // new (this) D2; // reuses storage - ends the lifetime of *this
- // f(); //undefined behavior
- // this; // OK, this points to valid memory
- // }
- // void g() {
- // void* p = malloc(sizeof(D1) + sizeof(D2));
- // B* pb = new (p) D1;
- // pb->mutate();
- // &pb; //OK: pb points to valid memory
- // void* q = pb; // OK: pb points to valid memory
- // pb->f(); //undefined behavior, lifetime of *pb has ended
- // }
- public void test3_8s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // struct C {
- // int i;
- // void f();
- // const C& operator=( const C& );
- // };
- // const C& C::operator=( const C& other)
- // {
- // if ( this != &other ) {
- // this->~C(); //lifetime of *this ends
- // new (this) C(other); // new object of type C created
- // f(); //welldefined
- // }
- // return *this;
- // }
- // int foo() {
- // C c1;
- // C c2;
- // c1 = c2; // welldefined
- // c1.f(); //welldefined; c1 refers to a new object of type C
- // }
- public void test3_8s7() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class T { };
- // struct B {
- // ~B();
- // };
- // void h() {
- // B b;
- // new (&b) T;
- // } //undefined behavior at block exit
- public void test3_8s8() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct B {
- // B();
- // ~B();
- // };
- // const B b;
- // void h() {
- // b.~B();
- // new (&b) const B; // undefined behavior
- // }
- public void test3_8s9() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // #define N sizeof(T)
- // void test() {
- // char buf[N];
- // T obj; // obj initialized to its original value
- // memcpy(buf, &obj, N); // between these two calls to memcpy,
- // // obj might be modified
- // memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type
- // // holds its original value
- // }
- public void test3_9s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // void test() {
- // T* t1p;
- // T* t2p;
- // // provided that t2p points to an initialized object ...
- // memcpy(t1p, t2p, sizeof(T)); // at this point, every subobject of POD type in *t1p contains
- // // the same value as the corresponding subobject in *t2p
- // }
- public void test3_9s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // class X; // X is an incomplete type
- // extern X* xp; // xp is a pointer to an incomplete type
- // extern int arr[]; // the type of arr is incomplete
- // typedef int UNKA[]; // UNKA is an incomplete type
- // UNKA* arrp; // arrp is a pointer to an incomplete type
- // UNKA** arrpp;
- // void foo() {
- // xp++; //ill-formed: X is incomplete
- // arrp++; //ill-formed: incomplete type
- // arrpp++; //OK: sizeof UNKA* is known
- // }
- // struct X {
- // int i;
- // }; // now X is a complete type
- // int arr[10]; // now the type of arr is complete
- // X x;
- // void bar() {
- // xp = &x; // OK; type is ''pointer to X''
- // arrp = &arr; // ill-formed: different types
- // xp++; //OK: X is complete
- // arrp++; //ill-formed: UNKA can't be completed
- // }
- public void test3_9s7() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int& f();
- public void test3_10s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // i = v[i++]; // the behavior is unspecified
- // i = 7, i++, i++; // i becomes 9
- // i = ++i + 1; // the behavior is unspecified
- // i = i + 1; // the value of i is incremented
- // }
- public void test5s4() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // struct B {};
- // struct D : B {};
- // void foo(D* dp)
- // {
- // B* bp = dynamic_cast<B*>(dp); // equivalent to B* bp = dp;
- // }
- public void test5_2_7s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class A { virtual void f(); };
- // class B { virtual void g(); };
- // class D : public virtual A, private B {};
- // void g()
- // {
- // D d;
- // B* bp = (B*)&d; // cast needed to break protection
- // A* ap = &d; // public derivation, no cast needed
- // D& dr = dynamic_cast<D&>(*bp); // fails
- // ap = dynamic_cast<A*>(bp); // fails
- // bp = dynamic_cast<B*>(ap); // fails
- // ap = dynamic_cast<A*>(&d); // succeeds
- // bp = dynamic_cast<B*>(&d); // fails
- // }
- // class E : public D, public B {};
- // class F : public E, public D {};
- // void h()
- // {
- // F f;
- // A* ap = &f; // succeeds: finds unique A
- // D* dp = dynamic_cast<D*>(ap); // fails: yields 0
- // // f has two D subobjects
- // E* ep = (E*)ap; // illformed:
- // // cast from virtual base
- // E* ep1 = dynamic_cast<E*>(ap); // succeeds
- // }
- public void test5_2_7s9() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class D { // ...
- // };
- // D d1;
- // const D d2;
- // int foo() {
- // typeid(d1) == typeid(d2); // yields true
- // typeid(D) == typeid(const D); // yields true
- // typeid(D) == typeid(d2); // yields true
- // typeid(D) == typeid(const D&); // yields true
- // }
- public void test5_2_8s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct B {};
- // struct D : public B {};
- // D d;
- // B &br = d;
- // int foo() {
- // static_cast<D&>(br); // produces lvalue to the original d object
- // }
- public void test5_2_9s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct A { int i; };
- // struct B : A { };
- // int foo() {
- // &B::i; // has type int A::*
- // }
- public void test5_3_1s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // void test() {
- // new (int (*[10])());
- // };
- public void test5_3_4s3() throws Exception {
- IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- IASTFunctionDefinition fdef= getDeclaration(tu, 0);
- IASTExpression expr= getExpressionOfStatement(fdef, 0);
- assertInstance(expr, ICPPASTNewExpression.class);
- ICPPASTNewExpression newExpr= (ICPPASTNewExpression) expr;
- assertNull(newExpr.getNewPlacement());
- assertNull(newExpr.getNewInitializer());
- IASTTypeId typeid= newExpr.getTypeId();
- isTypeEqual(CPPVisitor.createType(typeid), "int (* [10])()");
- }
- // typedef int T;
- // void test(int f) {
- // new T;
- // new(2,f) T;
- // new T[5];
- // new (2,f) T[5];
- // };
- public void test5_3_4s12() throws Exception {
- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236856
- IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- IASTFunctionDefinition fdef= getDeclaration(tu, 1);
- // new T;
- IASTExpression expr= getExpressionOfStatement(fdef, 0);
- assertInstance(expr, ICPPASTNewExpression.class);
- ICPPASTNewExpression newExpr= (ICPPASTNewExpression) expr;
- assertNull(newExpr.getNewPlacement());
- assertNull(newExpr.getNewInitializer());
- isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int");
- // new(2,f) T;
- expr= getExpressionOfStatement(fdef, 1);
- assertInstance(expr, ICPPASTNewExpression.class);
- newExpr= (ICPPASTNewExpression) expr;
- assertInstance(newExpr.getNewPlacement(), IASTExpressionList.class);
- assertNull(newExpr.getNewInitializer());
- isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int");
- // new T[5];
- expr= getExpressionOfStatement(fdef, 2);
- assertInstance(expr, ICPPASTNewExpression.class);
- newExpr= (ICPPASTNewExpression) expr;
- assertNull(newExpr.getNewPlacement());
- assertNull(newExpr.getNewInitializer());
- isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int [5]");
- // new (2,f) T[5];
- expr= getExpressionOfStatement(fdef, 3);
- assertInstance(expr, ICPPASTNewExpression.class);
- newExpr= (ICPPASTNewExpression) expr;
- assertInstance(newExpr.getNewPlacement(), IASTExpressionList.class);
- assertNull(newExpr.getNewInitializer());
- isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int [5]");
- }
- // int n=2;
- // int x=new float[n][5];
- // int y=new float[5][n];
- public void test5_3_4s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct A {};
- // struct I1 : A {};
- // struct I2 : A {};
- // struct D : I1, I2 {};
- // A *foo( D *p ) {
- // return (A*)( p ); // illformed
- // // static_cast interpretation
- // }
- public void test5_4s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // (ptr_to_obj->*ptr_to_mfct)(10);
- // }
- public void test5_5s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // void *p;
- // const int *q;
- // int **pi;
- // const int *const *pci;
- // void ct()
- // {
- // p <= q; // Both converted to const void * before comparison
- // pi <= pci; // Both converted to const int *const * before comparison
- // }
- public void test5_9s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct B {
- // int f();
- // };
- // struct L : B { };
- // struct R : B { };
- // struct D : L, R { };
- // int (B::*pb)() = &B::f;
- // int (L::*pl)() = pb;
- // int (R::*pr)() = pb;
- // int (D::*pdl)() = pl;
- // int (D::*pdr)() = pr;
- // bool x = (pdl == pdr); // false
- public void test5_10s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int f(int, int, int) {}
- // int foo() {
- // int a=0, t=1, c=2;
- // f(a, (t=3, t+2), c);
- // }
- public void test5_18s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // int x=0;
- // if (x)
- // int i;
- //
- // if (x) {
- // int i;
- // }
- // }
- public void test6_4s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // if (int x = 1) {
- // int x; // illformed,redeclaration of x
- // }
- // else {
- // int x; // illformed,redeclaration of x
- // }
- // }
- public void test6_4s3() throws Exception {
- // raised bug 90618
- // gcc does not report an error, either, so leave it as it is.
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // int x=5;
- // while (--x >= 0)
- // int i;
- // //can be equivalently rewritten as
- // while (--x >= 0) {
- // int i;
- // }
- // }
- public void test6_5s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct A {
- // int val;
- // A(int i) : val(i) { }
- // ~A() { }
- // operator bool() { return val != 0; }
- // };
- //
- // int foo() {
- // int i = 1;
- // while (A a = i) {
- // //...
- // i = 0;
- // }
- // }
- public void test6_5_1s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // int i = 42;
- // int a[10];
- // for (int i = 0; i < 10; i++)
- // a[i] = i;
- // int j = i; // j = 42
- // }
- public void test6_5_3s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // void f()
- // {
- // // ...
- // goto lx; // illformed: jump into scope of a
- // // ...
- // ly:
- // X a = 1; // X is undefined
- // // ...
- // lx:
- // goto ly; // OK, jump implies destructor
- // // call for a followed by construction
- // // again immediately following label ly
- // }
- public void test6_7s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 1);
- }
- // int foo(int i)
- // {
- // static int s = foo(2*i); // recursive call - undefined
- // return i+1;
- // }
- public void test6_7s4() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // T(a)->m = 7; // expressionstatement
- // T(a)++; //expressionstatement
- // T(a,5)<<c; //expressionstatement
- // T(*d)(int); //declaration
- // T(e)[5]; //declaration
- // T(f) = { 1, 2 }; // declaration
- // T(*g)(double(3)); // declaration
- // }
- public void test6_8s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // class T {
- // // ...
- // public:
- // T();
- // T(int);
- // T(int, int);
- // };
- // T(a); //declaration
- // T(*b)(); //declaration
- // T(c)=7; //declaration
- // T(d),e,f=3; //declaration
- // extern int h;
- // T(g)(h,2); //declaration
- public void test6_8s2() throws Exception { // TODO raised bug 90622
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct T1 {
- // T1 operator()(int x) { return T1(x); }
- // int operator=(int x) { return x; }
- // T1(int) { }
- // };
- // struct T2 { T2(int){ } };
- // int a, (*(*b)(T2))(int), c, d;
- // void f() {
- // // disambiguation requires this to be parsed
- // // as a declaration
- // T1(a) = 3,
- // T2(4), // T2 will be declared as
- // (*(*b)(T2(c)))(int(d)); // a variable of type T1
- // // but this will not allow
- // // the last part of the
- // // declaration to parse
- // // properly since it depends
- // // on T2 being a typename
- // }
- public void test6_8s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // typedef char* Pc;
- // void f(const Pc); // void f(char* const) (not const char*)
- // void g(const int Pc); // void g(const int)
- public void test7_1s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // void h(unsigned Pc); // void h(unsigned int)
- // void k(unsigned int Pc); // void k(unsigned int)
- public void test7_1s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // thread_local int e;
- // static thread_local int f;
- // extern thread_local int g;
- public void test7_1_1s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // static char* f(); // f() has internal linkage
- // char* f() // f() still has internal linkage
- // { //
- // }
- // char* g(); // g() has external linkage
- // static char* g() // error: inconsistent linkage
- // { //
- // }
- // void h();
- // inline void h(); // external linkage
- // inline void l();
- // void l(); // external linkage
- // inline void m();
- // extern void m(); // external linkage
- // static void n();
- // inline void n(); // internal linkage
- // static int a; // a has internal linkage
- // int a; // error: two definitions
- // static int b; // b has internal linkage
- // extern int b; // b still has internal linkage
- // int c; // c has external linkage
- // static int c; // error: inconsistent linkage
- // extern int d; // d has external linkage
- // static int d; // error: inconsistent linkage
- public void test7_1_1s7() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct S;
- // extern S a;
- // extern S f();
- // extern void g(S);
- // void h()
- // {
- // g(a); //error: S is incomplete
- // f(); //error: S is incomplete
- // }
- public void test7_1_1s8a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class X {
- // mutable const int* p; // OK
- // mutable int* const q; // illformed
- // };
- public void test7_1_1s8b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // typedef int MILES, *KLICKSP;
- // MILES distance;
- // extern KLICKSP metricp;
- public void test7_1_3s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // typedef struct s { //
- // } s;
- // typedef int I;
- // typedef int I;
- // typedef I I;
- public void test7_1_3s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class complex { //
- // };
- // typedef int complex; // error: redefinition
- public void test7_1_3s3a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // typedef int complex;
- // class complex { //
- // }; // error: redefinition
- public void test7_1_3s3b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct S {
- // S();
- // ~S();
- // };
- // typedef struct S T;
- // S a = T(); // OK
- // struct T * p; // error
- public void test7_1_3s4() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // typedef struct { } *ps, S; // S is the class name for linkage purposes
- public void test7_1_3s5a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // typedef struct {
- // S(); //error: requires a return type because S is
- // // an ordinary member function, not a constructor
- // } S;
- public void test7_1_3s5b() throws Exception {
- IASTTranslationUnit tu= parseWithErrors(getAboveComment(), ParserLanguage.CPP);
- IASTCompositeTypeSpecifier comp= getCompositeType(tu, 0);
- IASTDeclaration d= getDeclaration(comp, 0);
- assertInstance(d, IASTProblemDeclaration.class);
- }
- // constexpr int square(int x);
- // constexpr int bufsz = 1024;
- // struct pixel {
- // int x;
- // int y;
- // constexpr pixel(int);
- // };
- // constexpr pixel::pixel(int a)
- // : x(square(a)), y(square(a))
- // { }
- // constexpr int square(int x) {
- // return x * x;
- // }
- // constexpr pixel large(4);
- public void test7_1_5s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // const int ci = 3; // cvqualified (initialized as required)
- // ci = 4; // illformed: attempt to modify const
- // int i = 2; // not cvqualified
- // const int* cip; // pointer to const int
- // cip = &i; // OK: cvqualified access path to unqualified
- // *cip = 4; // illformed: attempt to modify through ptr to const
- // int* ip;
- // ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
- // *ip = 4; // defined: *ip points to i, a nonconst object
- // const int* ciq = new const int (3); // initialized as required
- // int* iq = const_cast<int*>(ciq); // cast required
- // *iq = 4; // undefined: modifies a const object
- // }
- public void test7_1_5_1s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class X {
- // public:
- // mutable int i;
- // int j;
- // };
- // class Y {
- // public:
- // X x;
- // Y();
- // };
- //
- // int foo() {
- // const Y y;
- // y.x.i++; //wellformed: mutable member can be modified
- // y.x.j++; //illformed: constqualified member modified
- // Y* p = const_cast<Y*>(&y); // cast away constness of y
- // p->x.i = 99; // wellformed: mutable member can be modified
- // p->x.j = 99; // undefined: modifies a const member
- // }
- public void test7_1_5_1s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // enum { a, b, c=0 };
- // enum { d, e, f=e+2 };
- public void test7_2s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // const int x = 12;
- // { enum { x = x }; }
- // }
- public void test7_2s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int foo() {
- // enum color { red, yellow, green=20, blue };
- // color col = red;
- // color* cp = &col;
- // if (*cp == blue) // ...
- // return 0;
- // }
- public void test7_2s8() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class X {
- // public:
- // enum direction { left='l', right='r' };
- // int f(int i)
- // { return i==left ? 0 : i==right ? 1 : 2; }
- // };
- // void g(X* p)
- // {
- // direction d; // error: direction not in scope
- // int i;
- // i = p->f(left); // error: left not in scope
- // i = p>
- // f(X::right); // OK
- // i = p>
- // f(p->left); // OK
- // // ...
- // }
- public void test7_2s10() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // namespace Outer {
- // int i;
- // namespace Inner {
- // void f() { i++; } // Outer::i
- // int i;
- // void g() { i++; } // Inner::i
- // }
- // }
- public void test7_3_1s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace { int i; } // unique::i
- // void f() { i++; } // unique::i++
- // namespace A {
- // namespace {
- // int i; // A::unique::i
- // int j; // A::unique::j
- // }
- // void g() { i++; } // A::unique::i++
- // }
- // using namespace A;
- // void h() {
- // i++; //error: unique::i or A::unique::i
- // A::i++; // A::unique::i
- // j++; // A::unique::j
- // }
- public void test7_3_1_1s1() throws Exception {
- String[] problems= {"i"};
- parse(getAboveComment(), ParserLanguage.CPP, problems);
- }
- // namespace X {
- // void f() { //
- // }
- // }
- public void test7_3_1_2s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace Q {
- // namespace V {
- // void f();
- // }
- // void V::f() { } // OK
- // void V::g() { } // error: g() is not yet a member of V
- // namespace V {
- // void g();
- // }
- // }
- // namespace R {
- // void Q::V::g() { } // error: R doesn't enclose Q
- // }
- public void test7_3_1_2s2() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 2);
- }
- // // Assume f and g have not yet been defined.
- // void h(int);
- // namespace A {
- // class X {
- // friend void f(X); // A::f is a friend
- // class Y {
- // friend void g(); // A::g is a friend
- // friend void h(int); // A::h is a friend
- // // ::h not considered
- // };
- // };
- // // A::f, A::g and A::h are not visible here
- // X x;
- // void g() { f(x); } // definition of A::g
- // void f(X) { } // definition of A::f
- // void h(int) { } // definition of A::h
- // // A::f, A::g and A::h are visible here and known to be friends
- // }
- // using A::x;
- // void h()
- // {
- // A::f(x);
- // A::X::f(x); //error: f is not a member of A::X
- // A::X::Y::g(); // error: g is not a member of A::X::Y
- // }
- public void test7_3_1_2s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 4);
- }
- // namespace Company_with_very_long_name { }
- // namespace CWVLN = Company_with_very_long_name;
- // namespace CWVLN = Company_with_very_long_name; // OK: duplicate
- // namespace CWVLN = CWVLN;
- public void test7_3_2s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct B {
- // void f(char);
- // void g(char);
- // enum E { e };
- // union { int x; };
- // };
- // struct D : B {
- // using B::f;
- // void f(int) { f('c'); } // calls B::f(char)
- // void g(int) { g('c'); } // recursively calls D::g(int)
- // };
- public void test7_3_3s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class C {
- // int g();
- // };
- // class D2 : public B {
- // using B::f; // OK: B is a base of D2
- // using B::e; // OK: e is an enumerator of base B
- // using B::x; // OK: x is a union member of base B
- // using C::g; // error: C isn't a base of D2
- // };
- public void test7_3_3s4() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // class A {
- // public:
- // template <class T> void f(T);
- // template <class T> struct X { };
- // };
- // class B : public A {
- // public:
- // using A::f<double>; // illformed
- // using A::X<int>; // illformed
- // };
- public void test7_3_3s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct X {
- // int i;
- // static int s;
- // };
- // void f()
- // {
- // using X::i; // error: X::i is a class member
- // // and this is not a member declaration.
- // using X::s; // error: X::s is a class member
- // // and this is not a member declaration.
- // }
- public void test7_3_3s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // void f();
- // namespace A {
- // void g();
- // }
- // namespace X {
- // using ::f; // global f
- // using A::g; // A's g
- // }
- // void h()
- // {
- // X::f(); //calls ::f
- // X::g(); //calls A::g
- // }
- public void test7_3_3s7() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // int i;
- // }
- // namespace A1 {
- // using A::i;
- // using A::i; // OK: double declaration
- // }
- // void f()
- // {
- // using A::i;
- // using A::i; // error: double declaration
- // }
- // class B {
- // public:
- // int i;
- // };
- // class X : public B {
- // using B::i;
- // using B::i; // error: double member declaration
- // };
- public void test7_3_3s8() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // void f(int);
- // }
- // using A::f; // f is a synonym for A::f;
- // // that is, for A::f(int).
- // namespace A {
- // void f(char);
- // }
- // void foo()
- // {
- // f('a'); //calls f(int),
- // } //even though f(char) exists.
- // void bar()
- // {
- // using A::f; // f is a synonym for A::f;
- // // that is, for A::f(int) and A::f(char).
- // f('a'); //calls f(char)
- // }
- public void test7_3_3s9() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct B {
- // virtual void f(int);
- // virtual void f(char);
- // void g(int);
- // void h(int);
- // };
- // struct D : B {
- // using B::f;
- // void f(int); // OK: D::f(int) overrides B::f(int);
- // using B::g;
- // void g(char); // OK
- // using B::h;
- // void h(int); // OK: D::h(int) hides B::h(int)
- // };
- // void k(D* p)
- // {
- // p->f(1); //calls D::f(int)
- // p->f('a'); //calls B::f(char)
- // p->g(1); //calls B::g(int)
- // p->g('a'); //calls D::g(char)
- // }
- public void test7_3_3s12() throws Exception { // raised bug 161562 for that
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // int x;
- // }
- // namespace B {
- // int i;
- // struct g { };
- // struct x { };
- // void f(int);
- // void f(double);
- // void g(char); // OK: hides struct g
- // }
- // void func()
- // {
- // int i;
- // //using B::i; // error: i declared twice
- // void f(char);
- // using B::f; // OK: each f is a function
- // f(3.5); //calls B::f(double)
- // using B::g;
- // g('a'); //calls B::g(char)
- // struct g g1; // g1 has class type B::g
- // using B::x;
- // using A::x; // OK: hides struct B::x
- // x = 99; // assigns to A::x
- // struct x x1; // x1 has class type B::x
- // }
- public void test7_3_3s10() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace B {
- // void f(int);
- // void f(double);
- // }
- // namespace C {
- // void f(int);
- // void f(double);
- // void f(char);
- // }
- // void h()
- // {
- // using B::f; // B::f(int) and B::f(double)
- // using C::f; // C::f(int), C::f(double), and C::f(char)
- // f('h'); //calls C::f(char)
- // f(1); //error: ambiguous: B::f(int) or C::f(int) ?
- // void f(int); // error:
- // // f(int) conflicts with C::f(int) and B::f(int)
- // }
- public void test7_3_3s11() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // struct A { int x(); };
- // struct B : A { };
- // struct C : A {
- // using A::x;
- // int x(int);
- // };
- // struct D : B, C {
- // using C::x;
- // int x(double);
- // };
- // int f(D* d) {
- // return d>
- // x(); // ambiguous: B::x or C::x
- // }
- public void test7_3_3s14() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // class A {
- // private:
- // void f(char);
- // public:
- // void f(int);
- // protected:
- // void g();
- // };
- // class B : public A {
- // using A::f; // error: A::f(char) is inaccessible
- // public:
- // using A::g; // B::g is a public synonym for A::g
- // };
- public void test7_3_3s15() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // int i;
- // namespace B {
- // namespace C {
- // int i;
- // }
- // using namespace A::B::C;
- // void f1() {
- // i = 5; // OK, C::i visible in B and hides A::i
- // }
- // }
- // namespace D {
- // using namespace B;
- // using namespace C;
- // void f2() {
- // i = 5; // ambiguous, B::C::i or A::i?
- // }
- // }
- // void f3() {
- // i = 5; // uses A::i
- // }
- // }
- // void f4() {
- // i = 5; // illformed; neither i is visible
- // }
- public void test7_3_4s1() throws Exception {
- String[] problems= {"i", "i"};
- parse(getAboveComment(), ParserLanguage.CPP, problems);
- }
- // namespace M {
- // int i;
- // }
- // namespace N {
- // int i;
- // using namespace M;
- // }
- // void f()
- // {
- // using namespace N;
- // i = 7; // error: both M::i and N::i are visible
- // }
- public void test7_3_4s2a() throws Exception {
- String[] problems= {"i"};
- parse(getAboveComment(), ParserLanguage.CPP, problems);
- }
- // namespace A {
- // int i;
- // }
- // namespace B {
- // int i;
- // int j;
- // namespace C {
- // namespace D {
- // using namespace A;
- // int j;
- // int k;
- // int a = i; // B::i hides A::i
- // }
- // using namespace D;
- // int k = 89; // no problem yet
- // int l = k; // ambiguous: C::k or D::k
- // int m = i; // B::i hides A::i
- // int n = j; // D::j hides B::j
- // }
- // }
- public void test7_3_4s2b() throws Exception {
- String[] problems= {"k"};
- parse(getAboveComment(), ParserLanguage.CPP, problems);
- }
- // namespace D {
- // int d1;
- // void f(char);
- // }
- // using namespace D;
- // int d1; // OK: no conflict with D::d1
- // namespace E {
- // int e;
- // void f(int);
- // }
- // namespace D { // namespace extension
- // int d2;
- // using namespace E;
- // void f(int);
- // }
- // void f()
- // {
- // d1++; //error: ambiguous ::d1 or D::d1?
- // ::d1++; //OK
- // D::d1++; //OK
- // d2++; //OK: D::d2
- // e++; //OK: E::e
- // f(1); //error: ambiguous: D::f(int) or E::f(int)?
- // f('a'); //OK: D::f(char)
- // }
- public void test7_3_4s5() throws Exception {
- String[] problems= {"d1", "f"};
- parse(getAboveComment(), ParserLanguage.CPP, problems);
- }
- // complex sqrt(complex); // C++ linkage by default
- // extern "C" {
- // double sqrt(double); // C linkage
- // }
- public void test7_5s3() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, false, 0);
- }
- // extern "C" void f1(void(*pf)(int));
- // // the name f1 and its function type have C language
- // // linkage; pf is a pointer to a C function
- // extern "C" typedef void FUNC();
- // FUNC f2; // the name f2 has C++ language linkage and the
- // // function's type has C language linkage
- // extern "C" FUNC f3; // the name of function f3 and the function's type
- // // have C language linkage
- // void (*pf2)(FUNC*); // the name of the variable pf2 has C++ linkage and
- // // the type of pf2 is pointer to C++ function that
- // // takes one parameter of type pointer to C function
- public void test7_5s4a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // extern "C" typedef void FUNC_c();
- // class C {
- // void mf1(FUNC_c*); // the name of the function mf1 and the member
- // // function's type have C++ language linkage; the
- // // parameter has type pointer to C function
- // FUNC_c mf2; // the name of the function mf2 and the member
- // // function's type have C++ language linkage
- // static FUNC_c* q; // the name of the data member q has C++ language
- // // linkage and the data member's type is pointer to
- // // C function
- // };
- // extern "C" {
- // class X {
- // void mf(); // the name of the function mf and the member
- // // function's type have C++ language linkage
- // void mf2(void(*)()); // the name of the function mf2 has C++ language
- // // linkage; the parameter has type pointer to
- // // C function
- // };
- // }
- public void test7_5s4b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // namespace A {
- // extern "C" int f();
- // extern "C" int g() { return 1; }
- // extern "C" int h();
- // }
- // namespace B {
- // extern "C" int f(); // A::f and B::f refer
- // // to the same function
- // extern "C" int g() { return 1; } // illformed,
- // // the function g
- // // with C language linkage
- // // has two definitions
- // }
- // int A::f() { return 98; } // definition for the function f
- // // with C language linkage
- // extern "C" int h() { return 97; }
- // // definition for the function h
- // // with C language linkage
- // // A::h and ::h refer to the same function
- public void test7_5s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // extern "C" double f();
- // static double f(); // error
- public void test7_5s7a() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // extern "C" int i; // declaration
- // extern "C" {
- // int i; // definition
- // }
- public void test7_5s7b() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // extern "C" static void f(); // error
- public void test7_5s7c() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // int i;
- // int *pi;
- // int *p[3];
- // int (*p3i)[3];
- // int *f();
- // int (*pf)(double);
- public void test8_1s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // struct S {
- // S(int);
- // };
- // void foo(double a)
- // {
- // S w(int(a)); // function declaration
- // S x(int()); // function declaration
- // S y((int)a); // object declaration
- // S z = int(a); // object declaration
- // }
- public void test8_2s1() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // template <class T>
- // struct S {
- // T *p;
- // };
- // S<int()> x; // typeid
- // S<int(1)> y; // expression (illformed)
- public void test8_2s4() throws Exception {
- IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 1);
- CPPNameCollector col = new CPPNameCollector();
- tu.accept(col);
- assertInstance(col.getName(4), ICPPASTTemplateId.class);
- assertInstance(((ICPPASTTemplateId)col.getName(4)).getTemplateArguments()[0], IASTTypeId.class);
- final IASTName S_int_1 = col.getName(7);
- assertInstance(S_int_1, ICPPASTTemplateId.class);
- assertInstance(((ICPPASTTemplateId)S_int_1).getTemplateArguments()[0], IASTExpression.class);
- assertInstance(S_int_1.getBinding(), IProblemBinding.class);
- }
- // void foo()
- // {
- // sizeof(int(1)); // expression
- // // sizeof(int()); // typeid (illformed)
- // }
- public void test8_2s5() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // void foo()
- // {
- // (int(1)); //expression
- // // (int())1; //typeid (illformed)
- // }
- public void test8_2s6() throws Exception {
- parse(getAboveComment(), ParserLanguage.CPP, true, 0);
- }
- // class C { };
- // void f(int(C)) { } // void f(int (*fp)(C c)) { }
- // // not: void f(int C);
- // int g(C);
- // void foo() {
- // f(1); //error: cannot convert 1 to function pointer
- // f(g); //OK
- // }
- public void test8_2s7a() throws Exception { // TODO raised bug 90633
- final String code = getAboveComment();
- parse(code, ParserLanguage.CPP, true, 1);
- BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
- IFunction f= ba.assertNonProblem("f", 1, IFunction.class);
- isTypeEqual(f.getType(), "void (int (*)(C))");
- }
- // class C { };
- // v…
Large files files are truncated, but you can click here to view the full file