PageRenderTime 123ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  1. /*******************************************************************************
  2. * Copyright (c) 2005, 2009 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Devin Steffler (IBM Corporation) - initial API and implementation
  10. * Markus Schorn (Wind River Systems)
  11. *******************************************************************************/
  12. package org.eclipse.cdt.core.parser.tests.ast2;
  13. import junit.framework.TestSuite;
  14. import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
  15. import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
  16. import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
  17. import org.eclipse.cdt.core.dom.ast.IASTExpression;
  18. import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
  19. import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
  20. import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
  21. import org.eclipse.cdt.core.dom.ast.IASTName;
  22. import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
  23. import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
  24. import org.eclipse.cdt.core.dom.ast.IASTTypeId;
  25. import org.eclipse.cdt.core.dom.ast.IBasicType;
  26. import org.eclipse.cdt.core.dom.ast.IBinding;
  27. import org.eclipse.cdt.core.dom.ast.IFunction;
  28. import org.eclipse.cdt.core.dom.ast.IProblemBinding;
  29. import org.eclipse.cdt.core.dom.ast.IType;
  30. import org.eclipse.cdt.core.dom.ast.ITypedef;
  31. import org.eclipse.cdt.core.dom.ast.IVariable;
  32. import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
  33. import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
  34. import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
  35. import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
  36. import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
  37. import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
  38. import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
  39. import org.eclipse.cdt.core.parser.ParserLanguage;
  40. import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
  41. import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
  42. /**
  43. * Examples taken from the c++-specification.
  44. */
  45. public class AST2CPPSpecTest extends AST2SpecBaseTest {
  46. public AST2CPPSpecTest() {
  47. }
  48. public AST2CPPSpecTest(String name) {
  49. super(name);
  50. }
  51. public static TestSuite suite() {
  52. return suite(AST2CPPSpecTest.class);
  53. }
  54. // int x=x+++++y;
  55. public void test2_4s5() throws Exception {
  56. parseCandCPP(getAboveComment(), false, 0);
  57. }
  58. // int a=12, b=014, c=0XC;
  59. public void test2_13_1s1() throws Exception {
  60. parseCandCPP(getAboveComment(), true, 0);
  61. }
  62. // ??=define arraycheck(a,b) a??(b??) ??!??! b??(a??)
  63. // // becomes
  64. // #define arraycheck(a,b) a[b] || b[a]
  65. public void test2_3s2() throws Exception { // TODO exists bug 64993
  66. parseCandCPP(getAboveComment(), true, 0);
  67. }
  68. // int a; // defines a
  69. // extern const int c = 1; // defines c
  70. // int f(int x) { return x+a; } // defines f and defines x
  71. // struct S { int a; int b; }; // defines S, S::a, and S::b
  72. // struct X { // defines X
  73. // int x; // defines nonstatic data member x
  74. // static int y; // declares static data member y
  75. // X(): x(0) { } // defines a constructor of X
  76. // };
  77. // int X::y = 1; // defines X::y
  78. // enum { up, down }; // defines up and down
  79. // namespace N { int d; } // defines N and N::d
  80. // namespace N1 = N; // defines N1
  81. // X anX; // defines anX
  82. // // whereas these are just declarations:
  83. // extern int a; // declares a
  84. // extern const int c; // declares c
  85. // int f(int); // declares f
  86. // struct S; // declares S
  87. // typedef int Int; // declares Int
  88. // extern X anotherX; // declares anotherX
  89. // using N::d; // declares N::d
  90. public void test3_1s3() throws Exception {
  91. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  92. }
  93. // struct C {
  94. // string s; // string is the standard library class (clause 21)
  95. // };
  96. // int main()
  97. // {
  98. // C a;
  99. // C b = a;
  100. // b = a;
  101. // }
  102. public void test3_1s4a() throws Exception {
  103. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  104. }
  105. // struct C {
  106. // string s;
  107. // C(): s() { }
  108. // C(const C& x): s(x.s) { }
  109. // C& operator=(const C& x) { s = x.s; return *this; }
  110. // ~C() { }
  111. // };
  112. //
  113. public void test3_1s4b() throws Exception {
  114. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  115. }
  116. // struct X; // declare X as a struct type
  117. // struct X* x1; // use X in pointer formation
  118. // X* x2; // use X in pointer formation
  119. public void test3_2s4() throws Exception {
  120. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  121. }
  122. // // translation unit 1:
  123. // struct X {
  124. // X(int);
  125. // X(int, int);
  126. // };
  127. // X::X(int = 0) { }
  128. // class D: public X { };
  129. // D d2; // X(int) called by D()
  130. public void test3_2s5_a() throws Exception {
  131. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  132. }
  133. // // translation unit 2:
  134. // struct X {
  135. // X(int);
  136. // X(int, int);
  137. // };
  138. // X::X(int = 0, int = 0) { }
  139. // class D: public X { }; // X(int, int) called by D();
  140. // // D()'s implicit definition
  141. // // violates the ODR
  142. public void test3_2s5_b() throws Exception {
  143. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  144. }
  145. // int j = 24;
  146. // int main()
  147. // {
  148. // int i = j, j;
  149. // j = 42;
  150. // }
  151. public void test3_3s2() throws Exception {
  152. parseCandCPP(getAboveComment(), true, 0);
  153. }
  154. // int foo() {
  155. // int x = 12;
  156. // { int x = x; }
  157. // }
  158. public void test3_3_1s1() throws Exception {
  159. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  160. }
  161. // int foo() {
  162. // const int i = 2;
  163. // { int i[i]; }
  164. // }
  165. public void test3_3_1s2() throws Exception {
  166. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  167. }
  168. // int foo() {
  169. // const int x = 12;
  170. // { enum { x = x }; }
  171. // }
  172. public void test3_3_1s3() throws Exception {
  173. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  174. }
  175. // namespace N {
  176. // int i;
  177. // int g(int a) { return a; }
  178. // int j();
  179. // void q();
  180. // }
  181. // namespace { int l=1; }
  182. // // the potential scope of l is from its point of declaration
  183. // // to the end of the translation unit
  184. // namespace N {
  185. // int g(char a) // overloads N::g(int)
  186. // {
  187. // return l+a; // l is from unnamed namespace
  188. // }
  189. // int i; // error: duplicate definition
  190. // int j(); // OK: duplicate function declaration
  191. // int j() // OK: definition of N::j()
  192. // {
  193. // return g(i); // calls N::g(int)
  194. // }
  195. // int q(); // error: different return type
  196. // }
  197. public void test3_3_5s1() throws Exception {
  198. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  199. }
  200. // namespace A {
  201. // namespace N {
  202. // void f();
  203. // }
  204. // }
  205. // void A::N::f() {
  206. // int i = 5;
  207. // // The following scopes are searched for a declaration of i:
  208. // // 1) outermost block scope of A::N::f, before the use of i
  209. // // 2) scope of namespace N
  210. // // 3) scope of namespace A
  211. // // 4) global scope, before the definition of A::N::f
  212. // }
  213. public void test3_4_1s6() throws Exception {
  214. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  215. }
  216. // namespace M {
  217. // class B { };
  218. // }
  219. public void test3_4_1s7() throws Exception {
  220. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  221. }
  222. // class B { };
  223. // namespace M {
  224. // namespace N {
  225. // class X : public B {
  226. // void f();
  227. // };
  228. // }
  229. // }
  230. // void M::N::X::f() {
  231. // int i = 16;
  232. // }
  233. // // The following scopes are searched for a declaration of i:
  234. // // 1) outermost block scope of M::N::X::f, before the use of i
  235. // // 2) scope of class M::N::X
  236. // // 3) scope of M::N::X's base class B
  237. // // 4) scope of namespace M::N
  238. // // 5) scope of namespace M
  239. // // 6) global scope, before the definition of M::N::X::f
  240. public void test3_4_1s8() throws Exception {
  241. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  242. }
  243. // struct A {
  244. // typedef int AT;
  245. // void f1(AT);
  246. // void f2(float);
  247. // };
  248. // struct B {
  249. // typedef float BT;
  250. // friend void A::f1(AT); // parameter type is A::AT
  251. // friend void A::f2(BT); // parameter type is B::BT
  252. // };
  253. public void test3_4_1s10() throws Exception {
  254. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  255. }
  256. // class A {
  257. // public:
  258. // static int n;
  259. // };
  260. // int main()
  261. // {
  262. // int A;
  263. // A::n = 42; // OK
  264. // A b; // illformed: A does not name a type
  265. // }
  266. public void test3_4_3s1() throws Exception {
  267. parse(getAboveComment(), ParserLanguage.CPP, true, 1);
  268. }
  269. // namespace NS {
  270. // class T { };
  271. // void f(T);
  272. // }
  273. // NS::T parm;
  274. // int main() {
  275. // f(parm); //OK: calls NS::f
  276. // }
  277. public void test3_4_2s2() throws Exception {
  278. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  279. }
  280. // class X { };
  281. // class C {
  282. // class X { };
  283. // static const int number = 50;
  284. // static X arr[number];
  285. // };
  286. // X C::arr[number]; // illformed:
  287. // // equivalent to: ::X C::arr[C::number];
  288. // // not to: C::X C::arr[C::number];
  289. public void test3_4_3s3() throws Exception {
  290. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  291. }
  292. // struct C {
  293. // typedef int I;
  294. // };
  295. // typedef int I1, I2;
  296. // int foo() {
  297. // extern int* p;
  298. // extern int* q;
  299. // p->C::I::~I(); // I is looked up in the scope of C
  300. // q->I1::~I2(); // I2 is looked up in the scope of
  301. // };
  302. // // the postfixexpression
  303. // struct A {
  304. // ~A();
  305. // };
  306. // typedef A AB;
  307. // int main()
  308. // {
  309. // AB *p;
  310. // p->AB::~AB(); // explicitly calls the destructor for A
  311. // }
  312. public void test3_4_3s5() throws Exception {
  313. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  314. }
  315. // int x;
  316. // namespace Y {
  317. // void f(float);
  318. // void h(int);
  319. // }
  320. // namespace Z {
  321. // void h(double);
  322. // }
  323. // namespace A {
  324. // using namespace Y;
  325. // void f(int);
  326. // void g(int);
  327. // int i;
  328. // }
  329. // namespace B {
  330. // using namespace Z;
  331. // void f(char);
  332. // int i;
  333. // }
  334. // namespace AB {
  335. // using namespace A;
  336. // using namespace B;
  337. // void g();
  338. // }
  339. // void h()
  340. // {
  341. // AB::g(); // g is declared directly in AB,
  342. // // therefore S is { AB::g() } and AB::g() is chosen
  343. // AB::f(1); // f is not declared directly in AB so the rules are
  344. // // applied recursively to A and B;
  345. // // namespace Y is not searched and Y::f(float)
  346. // // is not considered;
  347. // // S is { A::f(int), B::f(char) } and overload
  348. // // resolution chooses A::f(int)
  349. // AB::f('c'); //as above but resolution chooses B::f(char)
  350. // AB::x++; // x is not declared directly in AB, and
  351. // // is not declared in A or B, so the rules are
  352. // // applied recursively to Y and Z,
  353. // // S is { } so the program is illformed
  354. // AB::i++; // i is not declared directly in AB so the rules are
  355. // // applied recursively to A and B,
  356. // // S is { A::i, B::i } so the use is ambiguous
  357. // // and the program is illformed
  358. // AB::h(16.8); // h is not declared directly in AB and
  359. // // not declared directly in A or B so the rules are
  360. // // applied recursively to Y and Z,
  361. // // S is { Y::h(int), Z::h(double) } and overload
  362. // // resolution chooses Z::h(double)
  363. // }
  364. public void test3_4_3_2s2() throws Exception {
  365. String[] problems= {"AB::x", "x", "AB::i", "i"};
  366. parse(getAboveComment(), ParserLanguage.CPP, problems); // qualified names are counted double, so 4
  367. }
  368. // namespace A {
  369. // int a;
  370. // }
  371. // namespace B {
  372. // using namespace A;
  373. // }
  374. // namespace C {
  375. // using namespace A;
  376. // }
  377. // namespace BC {
  378. // using namespace B;
  379. // using namespace C;
  380. // }
  381. // void f()
  382. // {
  383. // BC::a++; //OK: S is { A::a, A::a }
  384. // }
  385. // namespace D {
  386. // using A::a;
  387. // }
  388. // namespace BD {
  389. // using namespace B;
  390. // using namespace D;
  391. // }
  392. // void g()
  393. // {
  394. // BD::a++; //OK: S is { A::a, A::a }
  395. // }
  396. public void test3_4_3_2s3() throws Exception {
  397. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  398. }
  399. // namespace B {
  400. // int b;
  401. // }
  402. // namespace A {
  403. // using namespace B;
  404. // int a;
  405. // }
  406. // namespace B {
  407. // using namespace A;
  408. // }
  409. // void f()
  410. // {
  411. // A::a++; //OK: a declared directly in A, S is { A::a }
  412. // B::a++; //OK: both A and B searched (once), S is { A::a }
  413. // A::b++; //OK: both A and B searched (once), S is { B::b }
  414. // B::b++; //OK: b declared directly in B, S is { B::b }
  415. // }
  416. public void test3_4_3_2s4() throws Exception {
  417. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  418. }
  419. // namespace A {
  420. // struct x { };
  421. // int x;
  422. // int y;
  423. // }
  424. // namespace B {
  425. // struct y {};
  426. // }
  427. // namespace C {
  428. // using namespace A;
  429. // using namespace B;
  430. // int i = C::x; // OK, A::x (of type int)
  431. // int j = C::y; // ambiguous, A::y or B::y
  432. // }
  433. public void test3_4_3_2s5() throws Exception {
  434. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  435. }
  436. // namespace A {
  437. // namespace B {
  438. // void f1(int);
  439. // }
  440. // using namespace B;
  441. // }
  442. // void A::f1(int) { } // illformed,
  443. // // f1 is not a member of A
  444. public void test3_4_3_2s6a() throws Exception {
  445. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  446. }
  447. // namespace A {
  448. // namespace B {
  449. // void f1(int);
  450. // }
  451. // }
  452. // namespace C {
  453. // namespace D {
  454. // void f1(int);
  455. // }
  456. // }
  457. // using namespace A;
  458. // using namespace C::D;
  459. // void B::f1(int){} // OK, defines A::B::f1(int)
  460. public void test3_4_3_2s6b() throws Exception {
  461. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  462. }
  463. // struct Node {
  464. // struct Node* Next; // OK: Refers to Node at global scope
  465. // struct Data* Data; // OK: Declares type Data
  466. // // at global scope and member Data
  467. // };
  468. // struct Data {
  469. // struct Node* Node; // OK: Refers to Node at global scope
  470. // friend struct ::Glob; // error: Glob is not declared
  471. // // cannot introduce a qualified type (7.1.5.3)
  472. // friend struct Glob; // OK: Refers to (as yet) undeclared Glob
  473. // // at global scope.
  474. //
  475. // };
  476. // struct Base {
  477. // struct Data; // OK: Declares nested Data
  478. // struct ::Data* thatData; // OK: Refers to ::Data
  479. // struct Base::Data* thisData; // OK: Refers to nested Data
  480. // friend class ::Data; // OK: global Data is a friend
  481. // friend class Data; // OK: nested Data is a friend
  482. // struct Data { //
  483. // }; // Defines nested Data
  484. // struct Data; // OK: Redeclares nested Data
  485. // };
  486. // struct Data; // OK: Redeclares Data at global scope
  487. // struct ::Data; // error: cannot introduce a qualified type (7.1.5.3)
  488. // struct Base::Data; // error: cannot introduce a qualified type (7.1.5.3)
  489. // struct Base::Datum; // error: Datum undefined
  490. // struct Base::Data* pBase; // OK: refers to nested Data
  491. public void test3_4_4s3() throws Exception {
  492. String[] problems= {"::Glob", "Glob", "Base::Datum", "Datum"};
  493. parse(getAboveComment(), ParserLanguage.CPP, problems);
  494. }
  495. // static void f();
  496. // static int i = 0; //1
  497. // void g() {
  498. // extern void f(); // internal linkage
  499. // int i; //2: i has no linkage
  500. // {
  501. // extern void f(); // internal linkage
  502. // extern int i; //3: external linkage
  503. // }
  504. // }
  505. public void test3_5s6() throws Exception {
  506. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  507. }
  508. // namespace X {
  509. // void p()
  510. // {
  511. // q(); //error: q not yet declared
  512. // extern void q(); // q is a member of namespace X
  513. // }
  514. // void middle()
  515. // {
  516. // q(); //error: q not yet declared
  517. // }
  518. // void q() { //
  519. // } // definition of X::q
  520. // }
  521. // void q() { //
  522. // } // some other, unrelated q
  523. public void test3_5s7() throws Exception {
  524. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  525. }
  526. // void f()
  527. // {
  528. // struct A { int x; }; // no linkage
  529. // extern A a; // illformed
  530. // typedef A B;
  531. // extern B b; // illformed
  532. // }
  533. public void test3_5s8() throws Exception {
  534. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  535. }
  536. // int main(int argc, char* argv[]) { //
  537. // }
  538. public void test3_6_1s2() throws Exception {
  539. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  540. }
  541. // struct B {
  542. // virtual void f();
  543. // void mutate();
  544. // virtual ~B();
  545. // };
  546. // struct D1 : B { void f(); };
  547. // struct D2 : B { void f(); };
  548. // void B::mutate() {
  549. // new (this) D2; // reuses storage - ends the lifetime of *this
  550. // f(); //undefined behavior
  551. // this; // OK, this points to valid memory
  552. // }
  553. // void g() {
  554. // void* p = malloc(sizeof(D1) + sizeof(D2));
  555. // B* pb = new (p) D1;
  556. // pb->mutate();
  557. // &pb; //OK: pb points to valid memory
  558. // void* q = pb; // OK: pb points to valid memory
  559. // pb->f(); //undefined behavior, lifetime of *pb has ended
  560. // }
  561. public void test3_8s5() throws Exception {
  562. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  563. }
  564. // struct C {
  565. // int i;
  566. // void f();
  567. // const C& operator=( const C& );
  568. // };
  569. // const C& C::operator=( const C& other)
  570. // {
  571. // if ( this != &other ) {
  572. // this->~C(); //lifetime of *this ends
  573. // new (this) C(other); // new object of type C created
  574. // f(); //welldefined
  575. // }
  576. // return *this;
  577. // }
  578. // int foo() {
  579. // C c1;
  580. // C c2;
  581. // c1 = c2; // welldefined
  582. // c1.f(); //welldefined; c1 refers to a new object of type C
  583. // }
  584. public void test3_8s7() throws Exception {
  585. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  586. }
  587. // class T { };
  588. // struct B {
  589. // ~B();
  590. // };
  591. // void h() {
  592. // B b;
  593. // new (&b) T;
  594. // } //undefined behavior at block exit
  595. public void test3_8s8() throws Exception {
  596. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  597. }
  598. // struct B {
  599. // B();
  600. // ~B();
  601. // };
  602. // const B b;
  603. // void h() {
  604. // b.~B();
  605. // new (&b) const B; // undefined behavior
  606. // }
  607. public void test3_8s9() throws Exception {
  608. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  609. }
  610. // #define N sizeof(T)
  611. // void test() {
  612. // char buf[N];
  613. // T obj; // obj initialized to its original value
  614. // memcpy(buf, &obj, N); // between these two calls to memcpy,
  615. // // obj might be modified
  616. // memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type
  617. // // holds its original value
  618. // }
  619. public void test3_9s2() throws Exception {
  620. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  621. }
  622. // void test() {
  623. // T* t1p;
  624. // T* t2p;
  625. // // provided that t2p points to an initialized object ...
  626. // memcpy(t1p, t2p, sizeof(T)); // at this point, every subobject of POD type in *t1p contains
  627. // // the same value as the corresponding subobject in *t2p
  628. // }
  629. public void test3_9s3() throws Exception {
  630. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  631. }
  632. // class X; // X is an incomplete type
  633. // extern X* xp; // xp is a pointer to an incomplete type
  634. // extern int arr[]; // the type of arr is incomplete
  635. // typedef int UNKA[]; // UNKA is an incomplete type
  636. // UNKA* arrp; // arrp is a pointer to an incomplete type
  637. // UNKA** arrpp;
  638. // void foo() {
  639. // xp++; //ill-formed: X is incomplete
  640. // arrp++; //ill-formed: incomplete type
  641. // arrpp++; //OK: sizeof UNKA* is known
  642. // }
  643. // struct X {
  644. // int i;
  645. // }; // now X is a complete type
  646. // int arr[10]; // now the type of arr is complete
  647. // X x;
  648. // void bar() {
  649. // xp = &x; // OK; type is ''pointer to X''
  650. // arrp = &arr; // ill-formed: different types
  651. // xp++; //OK: X is complete
  652. // arrp++; //ill-formed: UNKA can't be completed
  653. // }
  654. public void test3_9s7() throws Exception {
  655. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  656. }
  657. // int& f();
  658. public void test3_10s3() throws Exception {
  659. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  660. }
  661. // int foo() {
  662. // i = v[i++]; // the behavior is unspecified
  663. // i = 7, i++, i++; // i becomes 9
  664. // i = ++i + 1; // the behavior is unspecified
  665. // i = i + 1; // the value of i is incremented
  666. // }
  667. public void test5s4() throws Exception {
  668. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  669. }
  670. // struct B {};
  671. // struct D : B {};
  672. // void foo(D* dp)
  673. // {
  674. // B* bp = dynamic_cast<B*>(dp); // equivalent to B* bp = dp;
  675. // }
  676. public void test5_2_7s5() throws Exception {
  677. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  678. }
  679. // class A { virtual void f(); };
  680. // class B { virtual void g(); };
  681. // class D : public virtual A, private B {};
  682. // void g()
  683. // {
  684. // D d;
  685. // B* bp = (B*)&d; // cast needed to break protection
  686. // A* ap = &d; // public derivation, no cast needed
  687. // D& dr = dynamic_cast<D&>(*bp); // fails
  688. // ap = dynamic_cast<A*>(bp); // fails
  689. // bp = dynamic_cast<B*>(ap); // fails
  690. // ap = dynamic_cast<A*>(&d); // succeeds
  691. // bp = dynamic_cast<B*>(&d); // fails
  692. // }
  693. // class E : public D, public B {};
  694. // class F : public E, public D {};
  695. // void h()
  696. // {
  697. // F f;
  698. // A* ap = &f; // succeeds: finds unique A
  699. // D* dp = dynamic_cast<D*>(ap); // fails: yields 0
  700. // // f has two D subobjects
  701. // E* ep = (E*)ap; // illformed:
  702. // // cast from virtual base
  703. // E* ep1 = dynamic_cast<E*>(ap); // succeeds
  704. // }
  705. public void test5_2_7s9() throws Exception {
  706. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  707. }
  708. // class D { // ...
  709. // };
  710. // D d1;
  711. // const D d2;
  712. // int foo() {
  713. // typeid(d1) == typeid(d2); // yields true
  714. // typeid(D) == typeid(const D); // yields true
  715. // typeid(D) == typeid(d2); // yields true
  716. // typeid(D) == typeid(const D&); // yields true
  717. // }
  718. public void test5_2_8s5() throws Exception {
  719. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  720. }
  721. // struct B {};
  722. // struct D : public B {};
  723. // D d;
  724. // B &br = d;
  725. // int foo() {
  726. // static_cast<D&>(br); // produces lvalue to the original d object
  727. // }
  728. public void test5_2_9s5() throws Exception {
  729. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  730. }
  731. // struct A { int i; };
  732. // struct B : A { };
  733. // int foo() {
  734. // &B::i; // has type int A::*
  735. // }
  736. public void test5_3_1s2() throws Exception {
  737. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  738. }
  739. // void test() {
  740. // new (int (*[10])());
  741. // };
  742. public void test5_3_4s3() throws Exception {
  743. IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  744. IASTFunctionDefinition fdef= getDeclaration(tu, 0);
  745. IASTExpression expr= getExpressionOfStatement(fdef, 0);
  746. assertInstance(expr, ICPPASTNewExpression.class);
  747. ICPPASTNewExpression newExpr= (ICPPASTNewExpression) expr;
  748. assertNull(newExpr.getNewPlacement());
  749. assertNull(newExpr.getNewInitializer());
  750. IASTTypeId typeid= newExpr.getTypeId();
  751. isTypeEqual(CPPVisitor.createType(typeid), "int (* [10])()");
  752. }
  753. // typedef int T;
  754. // void test(int f) {
  755. // new T;
  756. // new(2,f) T;
  757. // new T[5];
  758. // new (2,f) T[5];
  759. // };
  760. public void test5_3_4s12() throws Exception {
  761. // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236856
  762. IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  763. IASTFunctionDefinition fdef= getDeclaration(tu, 1);
  764. // new T;
  765. IASTExpression expr= getExpressionOfStatement(fdef, 0);
  766. assertInstance(expr, ICPPASTNewExpression.class);
  767. ICPPASTNewExpression newExpr= (ICPPASTNewExpression) expr;
  768. assertNull(newExpr.getNewPlacement());
  769. assertNull(newExpr.getNewInitializer());
  770. isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int");
  771. // new(2,f) T;
  772. expr= getExpressionOfStatement(fdef, 1);
  773. assertInstance(expr, ICPPASTNewExpression.class);
  774. newExpr= (ICPPASTNewExpression) expr;
  775. assertInstance(newExpr.getNewPlacement(), IASTExpressionList.class);
  776. assertNull(newExpr.getNewInitializer());
  777. isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int");
  778. // new T[5];
  779. expr= getExpressionOfStatement(fdef, 2);
  780. assertInstance(expr, ICPPASTNewExpression.class);
  781. newExpr= (ICPPASTNewExpression) expr;
  782. assertNull(newExpr.getNewPlacement());
  783. assertNull(newExpr.getNewInitializer());
  784. isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int [5]");
  785. // new (2,f) T[5];
  786. expr= getExpressionOfStatement(fdef, 3);
  787. assertInstance(expr, ICPPASTNewExpression.class);
  788. newExpr= (ICPPASTNewExpression) expr;
  789. assertInstance(newExpr.getNewPlacement(), IASTExpressionList.class);
  790. assertNull(newExpr.getNewInitializer());
  791. isTypeEqual(CPPVisitor.createType(newExpr.getTypeId()), "int [5]");
  792. }
  793. // int n=2;
  794. // int x=new float[n][5];
  795. // int y=new float[5][n];
  796. public void test5_3_4s6() throws Exception {
  797. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  798. }
  799. // struct A {};
  800. // struct I1 : A {};
  801. // struct I2 : A {};
  802. // struct D : I1, I2 {};
  803. // A *foo( D *p ) {
  804. // return (A*)( p ); // illformed
  805. // // static_cast interpretation
  806. // }
  807. public void test5_4s5() throws Exception {
  808. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  809. }
  810. // int foo() {
  811. // (ptr_to_obj->*ptr_to_mfct)(10);
  812. // }
  813. public void test5_5s6() throws Exception {
  814. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  815. }
  816. // void *p;
  817. // const int *q;
  818. // int **pi;
  819. // const int *const *pci;
  820. // void ct()
  821. // {
  822. // p <= q; // Both converted to const void * before comparison
  823. // pi <= pci; // Both converted to const int *const * before comparison
  824. // }
  825. public void test5_9s2() throws Exception {
  826. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  827. }
  828. // struct B {
  829. // int f();
  830. // };
  831. // struct L : B { };
  832. // struct R : B { };
  833. // struct D : L, R { };
  834. // int (B::*pb)() = &B::f;
  835. // int (L::*pl)() = pb;
  836. // int (R::*pr)() = pb;
  837. // int (D::*pdl)() = pl;
  838. // int (D::*pdr)() = pr;
  839. // bool x = (pdl == pdr); // false
  840. public void test5_10s2() throws Exception {
  841. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  842. }
  843. // int f(int, int, int) {}
  844. // int foo() {
  845. // int a=0, t=1, c=2;
  846. // f(a, (t=3, t+2), c);
  847. // }
  848. public void test5_18s2() throws Exception {
  849. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  850. }
  851. // int foo() {
  852. // int x=0;
  853. // if (x)
  854. // int i;
  855. //
  856. // if (x) {
  857. // int i;
  858. // }
  859. // }
  860. public void test6_4s1() throws Exception {
  861. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  862. }
  863. // int foo() {
  864. // if (int x = 1) {
  865. // int x; // illformed,redeclaration of x
  866. // }
  867. // else {
  868. // int x; // illformed,redeclaration of x
  869. // }
  870. // }
  871. public void test6_4s3() throws Exception {
  872. // raised bug 90618
  873. // gcc does not report an error, either, so leave it as it is.
  874. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  875. }
  876. // int foo() {
  877. // int x=5;
  878. // while (--x >= 0)
  879. // int i;
  880. // //can be equivalently rewritten as
  881. // while (--x >= 0) {
  882. // int i;
  883. // }
  884. // }
  885. public void test6_5s3() throws Exception {
  886. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  887. }
  888. // struct A {
  889. // int val;
  890. // A(int i) : val(i) { }
  891. // ~A() { }
  892. // operator bool() { return val != 0; }
  893. // };
  894. //
  895. // int foo() {
  896. // int i = 1;
  897. // while (A a = i) {
  898. // //...
  899. // i = 0;
  900. // }
  901. // }
  902. public void test6_5_1s2() throws Exception {
  903. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  904. }
  905. // int foo() {
  906. // int i = 42;
  907. // int a[10];
  908. // for (int i = 0; i < 10; i++)
  909. // a[i] = i;
  910. // int j = i; // j = 42
  911. // }
  912. public void test6_5_3s3() throws Exception {
  913. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  914. }
  915. // void f()
  916. // {
  917. // // ...
  918. // goto lx; // illformed: jump into scope of a
  919. // // ...
  920. // ly:
  921. // X a = 1; // X is undefined
  922. // // ...
  923. // lx:
  924. // goto ly; // OK, jump implies destructor
  925. // // call for a followed by construction
  926. // // again immediately following label ly
  927. // }
  928. public void test6_7s3() throws Exception {
  929. parse(getAboveComment(), ParserLanguage.CPP, true, 1);
  930. }
  931. // int foo(int i)
  932. // {
  933. // static int s = foo(2*i); // recursive call - undefined
  934. // return i+1;
  935. // }
  936. public void test6_7s4() throws Exception {
  937. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  938. }
  939. // int foo() {
  940. // T(a)->m = 7; // expressionstatement
  941. // T(a)++; //expressionstatement
  942. // T(a,5)<<c; //expressionstatement
  943. // T(*d)(int); //declaration
  944. // T(e)[5]; //declaration
  945. // T(f) = { 1, 2 }; // declaration
  946. // T(*g)(double(3)); // declaration
  947. // }
  948. public void test6_8s1() throws Exception {
  949. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  950. }
  951. // class T {
  952. // // ...
  953. // public:
  954. // T();
  955. // T(int);
  956. // T(int, int);
  957. // };
  958. // T(a); //declaration
  959. // T(*b)(); //declaration
  960. // T(c)=7; //declaration
  961. // T(d),e,f=3; //declaration
  962. // extern int h;
  963. // T(g)(h,2); //declaration
  964. public void test6_8s2() throws Exception { // TODO raised bug 90622
  965. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  966. }
  967. // struct T1 {
  968. // T1 operator()(int x) { return T1(x); }
  969. // int operator=(int x) { return x; }
  970. // T1(int) { }
  971. // };
  972. // struct T2 { T2(int){ } };
  973. // int a, (*(*b)(T2))(int), c, d;
  974. // void f() {
  975. // // disambiguation requires this to be parsed
  976. // // as a declaration
  977. // T1(a) = 3,
  978. // T2(4), // T2 will be declared as
  979. // (*(*b)(T2(c)))(int(d)); // a variable of type T1
  980. // // but this will not allow
  981. // // the last part of the
  982. // // declaration to parse
  983. // // properly since it depends
  984. // // on T2 being a typename
  985. // }
  986. public void test6_8s3() throws Exception {
  987. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  988. }
  989. // typedef char* Pc;
  990. // void f(const Pc); // void f(char* const) (not const char*)
  991. // void g(const int Pc); // void g(const int)
  992. public void test7_1s2() throws Exception {
  993. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  994. }
  995. // void h(unsigned Pc); // void h(unsigned int)
  996. // void k(unsigned int Pc); // void k(unsigned int)
  997. public void test7_1s3() throws Exception {
  998. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  999. }
  1000. // thread_local int e;
  1001. // static thread_local int f;
  1002. // extern thread_local int g;
  1003. public void test7_1_1s1() throws Exception {
  1004. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1005. }
  1006. // static char* f(); // f() has internal linkage
  1007. // char* f() // f() still has internal linkage
  1008. // { //
  1009. // }
  1010. // char* g(); // g() has external linkage
  1011. // static char* g() // error: inconsistent linkage
  1012. // { //
  1013. // }
  1014. // void h();
  1015. // inline void h(); // external linkage
  1016. // inline void l();
  1017. // void l(); // external linkage
  1018. // inline void m();
  1019. // extern void m(); // external linkage
  1020. // static void n();
  1021. // inline void n(); // internal linkage
  1022. // static int a; // a has internal linkage
  1023. // int a; // error: two definitions
  1024. // static int b; // b has internal linkage
  1025. // extern int b; // b still has internal linkage
  1026. // int c; // c has external linkage
  1027. // static int c; // error: inconsistent linkage
  1028. // extern int d; // d has external linkage
  1029. // static int d; // error: inconsistent linkage
  1030. public void test7_1_1s7() throws Exception {
  1031. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1032. }
  1033. // struct S;
  1034. // extern S a;
  1035. // extern S f();
  1036. // extern void g(S);
  1037. // void h()
  1038. // {
  1039. // g(a); //error: S is incomplete
  1040. // f(); //error: S is incomplete
  1041. // }
  1042. public void test7_1_1s8a() throws Exception {
  1043. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1044. }
  1045. // class X {
  1046. // mutable const int* p; // OK
  1047. // mutable int* const q; // illformed
  1048. // };
  1049. public void test7_1_1s8b() throws Exception {
  1050. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1051. }
  1052. // typedef int MILES, *KLICKSP;
  1053. // MILES distance;
  1054. // extern KLICKSP metricp;
  1055. public void test7_1_3s1() throws Exception {
  1056. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1057. }
  1058. // typedef struct s { //
  1059. // } s;
  1060. // typedef int I;
  1061. // typedef int I;
  1062. // typedef I I;
  1063. public void test7_1_3s2() throws Exception {
  1064. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1065. }
  1066. // class complex { //
  1067. // };
  1068. // typedef int complex; // error: redefinition
  1069. public void test7_1_3s3a() throws Exception {
  1070. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1071. }
  1072. // typedef int complex;
  1073. // class complex { //
  1074. // }; // error: redefinition
  1075. public void test7_1_3s3b() throws Exception {
  1076. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1077. }
  1078. // struct S {
  1079. // S();
  1080. // ~S();
  1081. // };
  1082. // typedef struct S T;
  1083. // S a = T(); // OK
  1084. // struct T * p; // error
  1085. public void test7_1_3s4() throws Exception {
  1086. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1087. }
  1088. // typedef struct { } *ps, S; // S is the class name for linkage purposes
  1089. public void test7_1_3s5a() throws Exception {
  1090. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1091. }
  1092. // typedef struct {
  1093. // S(); //error: requires a return type because S is
  1094. // // an ordinary member function, not a constructor
  1095. // } S;
  1096. public void test7_1_3s5b() throws Exception {
  1097. IASTTranslationUnit tu= parseWithErrors(getAboveComment(), ParserLanguage.CPP);
  1098. IASTCompositeTypeSpecifier comp= getCompositeType(tu, 0);
  1099. IASTDeclaration d= getDeclaration(comp, 0);
  1100. assertInstance(d, IASTProblemDeclaration.class);
  1101. }
  1102. // constexpr int square(int x);
  1103. // constexpr int bufsz = 1024;
  1104. // struct pixel {
  1105. // int x;
  1106. // int y;
  1107. // constexpr pixel(int);
  1108. // };
  1109. // constexpr pixel::pixel(int a)
  1110. // : x(square(a)), y(square(a))
  1111. // { }
  1112. // constexpr int square(int x) {
  1113. // return x * x;
  1114. // }
  1115. // constexpr pixel large(4);
  1116. public void test7_1_5s1() throws Exception {
  1117. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1118. }
  1119. // int foo() {
  1120. // const int ci = 3; // cvqualified (initialized as required)
  1121. // ci = 4; // illformed: attempt to modify const
  1122. // int i = 2; // not cvqualified
  1123. // const int* cip; // pointer to const int
  1124. // cip = &i; // OK: cvqualified access path to unqualified
  1125. // *cip = 4; // illformed: attempt to modify through ptr to const
  1126. // int* ip;
  1127. // ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
  1128. // *ip = 4; // defined: *ip points to i, a nonconst object
  1129. // const int* ciq = new const int (3); // initialized as required
  1130. // int* iq = const_cast<int*>(ciq); // cast required
  1131. // *iq = 4; // undefined: modifies a const object
  1132. // }
  1133. public void test7_1_5_1s5() throws Exception {
  1134. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1135. }
  1136. // class X {
  1137. // public:
  1138. // mutable int i;
  1139. // int j;
  1140. // };
  1141. // class Y {
  1142. // public:
  1143. // X x;
  1144. // Y();
  1145. // };
  1146. //
  1147. // int foo() {
  1148. // const Y y;
  1149. // y.x.i++; //wellformed: mutable member can be modified
  1150. // y.x.j++; //illformed: constqualified member modified
  1151. // Y* p = const_cast<Y*>(&y); // cast away constness of y
  1152. // p->x.i = 99; // wellformed: mutable member can be modified
  1153. // p->x.j = 99; // undefined: modifies a const member
  1154. // }
  1155. public void test7_1_5_1s6() throws Exception {
  1156. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1157. }
  1158. // enum { a, b, c=0 };
  1159. // enum { d, e, f=e+2 };
  1160. public void test7_2s2() throws Exception {
  1161. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1162. }
  1163. // int foo() {
  1164. // const int x = 12;
  1165. // { enum { x = x }; }
  1166. // }
  1167. public void test7_2s3() throws Exception {
  1168. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1169. }
  1170. // int foo() {
  1171. // enum color { red, yellow, green=20, blue };
  1172. // color col = red;
  1173. // color* cp = &col;
  1174. // if (*cp == blue) // ...
  1175. // return 0;
  1176. // }
  1177. public void test7_2s8() throws Exception {
  1178. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1179. }
  1180. // class X {
  1181. // public:
  1182. // enum direction { left='l', right='r' };
  1183. // int f(int i)
  1184. // { return i==left ? 0 : i==right ? 1 : 2; }
  1185. // };
  1186. // void g(X* p)
  1187. // {
  1188. // direction d; // error: direction not in scope
  1189. // int i;
  1190. // i = p->f(left); // error: left not in scope
  1191. // i = p>
  1192. // f(X::right); // OK
  1193. // i = p>
  1194. // f(p->left); // OK
  1195. // // ...
  1196. // }
  1197. public void test7_2s10() throws Exception {
  1198. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  1199. }
  1200. // namespace Outer {
  1201. // int i;
  1202. // namespace Inner {
  1203. // void f() { i++; } // Outer::i
  1204. // int i;
  1205. // void g() { i++; } // Inner::i
  1206. // }
  1207. // }
  1208. public void test7_3_1s5() throws Exception {
  1209. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1210. }
  1211. // namespace { int i; } // unique::i
  1212. // void f() { i++; } // unique::i++
  1213. // namespace A {
  1214. // namespace {
  1215. // int i; // A::unique::i
  1216. // int j; // A::unique::j
  1217. // }
  1218. // void g() { i++; } // A::unique::i++
  1219. // }
  1220. // using namespace A;
  1221. // void h() {
  1222. // i++; //error: unique::i or A::unique::i
  1223. // A::i++; // A::unique::i
  1224. // j++; // A::unique::j
  1225. // }
  1226. public void test7_3_1_1s1() throws Exception {
  1227. String[] problems= {"i"};
  1228. parse(getAboveComment(), ParserLanguage.CPP, problems);
  1229. }
  1230. // namespace X {
  1231. // void f() { //
  1232. // }
  1233. // }
  1234. public void test7_3_1_2s1() throws Exception {
  1235. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1236. }
  1237. // namespace Q {
  1238. // namespace V {
  1239. // void f();
  1240. // }
  1241. // void V::f() { } // OK
  1242. // void V::g() { } // error: g() is not yet a member of V
  1243. // namespace V {
  1244. // void g();
  1245. // }
  1246. // }
  1247. // namespace R {
  1248. // void Q::V::g() { } // error: R doesn't enclose Q
  1249. // }
  1250. public void test7_3_1_2s2() throws Exception {
  1251. parse(getAboveComment(), ParserLanguage.CPP, true, 2);
  1252. }
  1253. // // Assume f and g have not yet been defined.
  1254. // void h(int);
  1255. // namespace A {
  1256. // class X {
  1257. // friend void f(X); // A::f is a friend
  1258. // class Y {
  1259. // friend void g(); // A::g is a friend
  1260. // friend void h(int); // A::h is a friend
  1261. // // ::h not considered
  1262. // };
  1263. // };
  1264. // // A::f, A::g and A::h are not visible here
  1265. // X x;
  1266. // void g() { f(x); } // definition of A::g
  1267. // void f(X) { } // definition of A::f
  1268. // void h(int) { } // definition of A::h
  1269. // // A::f, A::g and A::h are visible here and known to be friends
  1270. // }
  1271. // using A::x;
  1272. // void h()
  1273. // {
  1274. // A::f(x);
  1275. // A::X::f(x); //error: f is not a member of A::X
  1276. // A::X::Y::g(); // error: g is not a member of A::X::Y
  1277. // }
  1278. public void test7_3_1_2s3() throws Exception {
  1279. parse(getAboveComment(), ParserLanguage.CPP, true, 4);
  1280. }
  1281. // namespace Company_with_very_long_name { }
  1282. // namespace CWVLN = Company_with_very_long_name;
  1283. // namespace CWVLN = Company_with_very_long_name; // OK: duplicate
  1284. // namespace CWVLN = CWVLN;
  1285. public void test7_3_2s3() throws Exception {
  1286. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1287. }
  1288. // struct B {
  1289. // void f(char);
  1290. // void g(char);
  1291. // enum E { e };
  1292. // union { int x; };
  1293. // };
  1294. // struct D : B {
  1295. // using B::f;
  1296. // void f(int) { f('c'); } // calls B::f(char)
  1297. // void g(int) { g('c'); } // recursively calls D::g(int)
  1298. // };
  1299. public void test7_3_3s3() throws Exception {
  1300. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1301. }
  1302. // class C {
  1303. // int g();
  1304. // };
  1305. // class D2 : public B {
  1306. // using B::f; // OK: B is a base of D2
  1307. // using B::e; // OK: e is an enumerator of base B
  1308. // using B::x; // OK: x is a union member of base B
  1309. // using C::g; // error: C isn't a base of D2
  1310. // };
  1311. public void test7_3_3s4() throws Exception {
  1312. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  1313. }
  1314. // class A {
  1315. // public:
  1316. // template <class T> void f(T);
  1317. // template <class T> struct X { };
  1318. // };
  1319. // class B : public A {
  1320. // public:
  1321. // using A::f<double>; // illformed
  1322. // using A::X<int>; // illformed
  1323. // };
  1324. public void test7_3_3s5() throws Exception {
  1325. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1326. }
  1327. // struct X {
  1328. // int i;
  1329. // static int s;
  1330. // };
  1331. // void f()
  1332. // {
  1333. // using X::i; // error: X::i is a class member
  1334. // // and this is not a member declaration.
  1335. // using X::s; // error: X::s is a class member
  1336. // // and this is not a member declaration.
  1337. // }
  1338. public void test7_3_3s6() throws Exception {
  1339. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1340. }
  1341. // void f();
  1342. // namespace A {
  1343. // void g();
  1344. // }
  1345. // namespace X {
  1346. // using ::f; // global f
  1347. // using A::g; // A's g
  1348. // }
  1349. // void h()
  1350. // {
  1351. // X::f(); //calls ::f
  1352. // X::g(); //calls A::g
  1353. // }
  1354. public void test7_3_3s7() throws Exception {
  1355. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1356. }
  1357. // namespace A {
  1358. // int i;
  1359. // }
  1360. // namespace A1 {
  1361. // using A::i;
  1362. // using A::i; // OK: double declaration
  1363. // }
  1364. // void f()
  1365. // {
  1366. // using A::i;
  1367. // using A::i; // error: double declaration
  1368. // }
  1369. // class B {
  1370. // public:
  1371. // int i;
  1372. // };
  1373. // class X : public B {
  1374. // using B::i;
  1375. // using B::i; // error: double member declaration
  1376. // };
  1377. public void test7_3_3s8() throws Exception {
  1378. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1379. }
  1380. // namespace A {
  1381. // void f(int);
  1382. // }
  1383. // using A::f; // f is a synonym for A::f;
  1384. // // that is, for A::f(int).
  1385. // namespace A {
  1386. // void f(char);
  1387. // }
  1388. // void foo()
  1389. // {
  1390. // f('a'); //calls f(int),
  1391. // } //even though f(char) exists.
  1392. // void bar()
  1393. // {
  1394. // using A::f; // f is a synonym for A::f;
  1395. // // that is, for A::f(int) and A::f(char).
  1396. // f('a'); //calls f(char)
  1397. // }
  1398. public void test7_3_3s9() throws Exception {
  1399. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1400. }
  1401. // struct B {
  1402. // virtual void f(int);
  1403. // virtual void f(char);
  1404. // void g(int);
  1405. // void h(int);
  1406. // };
  1407. // struct D : B {
  1408. // using B::f;
  1409. // void f(int); // OK: D::f(int) overrides B::f(int);
  1410. // using B::g;
  1411. // void g(char); // OK
  1412. // using B::h;
  1413. // void h(int); // OK: D::h(int) hides B::h(int)
  1414. // };
  1415. // void k(D* p)
  1416. // {
  1417. // p->f(1); //calls D::f(int)
  1418. // p->f('a'); //calls B::f(char)
  1419. // p->g(1); //calls B::g(int)
  1420. // p->g('a'); //calls D::g(char)
  1421. // }
  1422. public void test7_3_3s12() throws Exception { // raised bug 161562 for that
  1423. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1424. }
  1425. // namespace A {
  1426. // int x;
  1427. // }
  1428. // namespace B {
  1429. // int i;
  1430. // struct g { };
  1431. // struct x { };
  1432. // void f(int);
  1433. // void f(double);
  1434. // void g(char); // OK: hides struct g
  1435. // }
  1436. // void func()
  1437. // {
  1438. // int i;
  1439. // //using B::i; // error: i declared twice
  1440. // void f(char);
  1441. // using B::f; // OK: each f is a function
  1442. // f(3.5); //calls B::f(double)
  1443. // using B::g;
  1444. // g('a'); //calls B::g(char)
  1445. // struct g g1; // g1 has class type B::g
  1446. // using B::x;
  1447. // using A::x; // OK: hides struct B::x
  1448. // x = 99; // assigns to A::x
  1449. // struct x x1; // x1 has class type B::x
  1450. // }
  1451. public void test7_3_3s10() throws Exception {
  1452. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1453. }
  1454. // namespace B {
  1455. // void f(int);
  1456. // void f(double);
  1457. // }
  1458. // namespace C {
  1459. // void f(int);
  1460. // void f(double);
  1461. // void f(char);
  1462. // }
  1463. // void h()
  1464. // {
  1465. // using B::f; // B::f(int) and B::f(double)
  1466. // using C::f; // C::f(int), C::f(double), and C::f(char)
  1467. // f('h'); //calls C::f(char)
  1468. // f(1); //error: ambiguous: B::f(int) or C::f(int) ?
  1469. // void f(int); // error:
  1470. // // f(int) conflicts with C::f(int) and B::f(int)
  1471. // }
  1472. public void test7_3_3s11() throws Exception {
  1473. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  1474. }
  1475. // struct A { int x(); };
  1476. // struct B : A { };
  1477. // struct C : A {
  1478. // using A::x;
  1479. // int x(int);
  1480. // };
  1481. // struct D : B, C {
  1482. // using C::x;
  1483. // int x(double);
  1484. // };
  1485. // int f(D* d) {
  1486. // return d>
  1487. // x(); // ambiguous: B::x or C::x
  1488. // }
  1489. public void test7_3_3s14() throws Exception {
  1490. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  1491. }
  1492. // class A {
  1493. // private:
  1494. // void f(char);
  1495. // public:
  1496. // void f(int);
  1497. // protected:
  1498. // void g();
  1499. // };
  1500. // class B : public A {
  1501. // using A::f; // error: A::f(char) is inaccessible
  1502. // public:
  1503. // using A::g; // B::g is a public synonym for A::g
  1504. // };
  1505. public void test7_3_3s15() throws Exception {
  1506. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1507. }
  1508. // namespace A {
  1509. // int i;
  1510. // namespace B {
  1511. // namespace C {
  1512. // int i;
  1513. // }
  1514. // using namespace A::B::C;
  1515. // void f1() {
  1516. // i = 5; // OK, C::i visible in B and hides A::i
  1517. // }
  1518. // }
  1519. // namespace D {
  1520. // using namespace B;
  1521. // using namespace C;
  1522. // void f2() {
  1523. // i = 5; // ambiguous, B::C::i or A::i?
  1524. // }
  1525. // }
  1526. // void f3() {
  1527. // i = 5; // uses A::i
  1528. // }
  1529. // }
  1530. // void f4() {
  1531. // i = 5; // illformed; neither i is visible
  1532. // }
  1533. public void test7_3_4s1() throws Exception {
  1534. String[] problems= {"i", "i"};
  1535. parse(getAboveComment(), ParserLanguage.CPP, problems);
  1536. }
  1537. // namespace M {
  1538. // int i;
  1539. // }
  1540. // namespace N {
  1541. // int i;
  1542. // using namespace M;
  1543. // }
  1544. // void f()
  1545. // {
  1546. // using namespace N;
  1547. // i = 7; // error: both M::i and N::i are visible
  1548. // }
  1549. public void test7_3_4s2a() throws Exception {
  1550. String[] problems= {"i"};
  1551. parse(getAboveComment(), ParserLanguage.CPP, problems);
  1552. }
  1553. // namespace A {
  1554. // int i;
  1555. // }
  1556. // namespace B {
  1557. // int i;
  1558. // int j;
  1559. // namespace C {
  1560. // namespace D {
  1561. // using namespace A;
  1562. // int j;
  1563. // int k;
  1564. // int a = i; // B::i hides A::i
  1565. // }
  1566. // using namespace D;
  1567. // int k = 89; // no problem yet
  1568. // int l = k; // ambiguous: C::k or D::k
  1569. // int m = i; // B::i hides A::i
  1570. // int n = j; // D::j hides B::j
  1571. // }
  1572. // }
  1573. public void test7_3_4s2b() throws Exception {
  1574. String[] problems= {"k"};
  1575. parse(getAboveComment(), ParserLanguage.CPP, problems);
  1576. }
  1577. // namespace D {
  1578. // int d1;
  1579. // void f(char);
  1580. // }
  1581. // using namespace D;
  1582. // int d1; // OK: no conflict with D::d1
  1583. // namespace E {
  1584. // int e;
  1585. // void f(int);
  1586. // }
  1587. // namespace D { // namespace extension
  1588. // int d2;
  1589. // using namespace E;
  1590. // void f(int);
  1591. // }
  1592. // void f()
  1593. // {
  1594. // d1++; //error: ambiguous ::d1 or D::d1?
  1595. // ::d1++; //OK
  1596. // D::d1++; //OK
  1597. // d2++; //OK: D::d2
  1598. // e++; //OK: E::e
  1599. // f(1); //error: ambiguous: D::f(int) or E::f(int)?
  1600. // f('a'); //OK: D::f(char)
  1601. // }
  1602. public void test7_3_4s5() throws Exception {
  1603. String[] problems= {"d1", "f"};
  1604. parse(getAboveComment(), ParserLanguage.CPP, problems);
  1605. }
  1606. // complex sqrt(complex); // C++ linkage by default
  1607. // extern "C" {
  1608. // double sqrt(double); // C linkage
  1609. // }
  1610. public void test7_5s3() throws Exception {
  1611. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  1612. }
  1613. // extern "C" void f1(void(*pf)(int));
  1614. // // the name f1 and its function type have C language
  1615. // // linkage; pf is a pointer to a C function
  1616. // extern "C" typedef void FUNC();
  1617. // FUNC f2; // the name f2 has C++ language linkage and the
  1618. // // function's type has C language linkage
  1619. // extern "C" FUNC f3; // the name of function f3 and the function's type
  1620. // // have C language linkage
  1621. // void (*pf2)(FUNC*); // the name of the variable pf2 has C++ linkage and
  1622. // // the type of pf2 is pointer to C++ function that
  1623. // // takes one parameter of type pointer to C function
  1624. public void test7_5s4a() throws Exception {
  1625. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1626. }
  1627. // extern "C" typedef void FUNC_c();
  1628. // class C {
  1629. // void mf1(FUNC_c*); // the name of the function mf1 and the member
  1630. // // function's type have C++ language linkage; the
  1631. // // parameter has type pointer to C function
  1632. // FUNC_c mf2; // the name of the function mf2 and the member
  1633. // // function's type have C++ language linkage
  1634. // static FUNC_c* q; // the name of the data member q has C++ language
  1635. // // linkage and the data member's type is pointer to
  1636. // // C function
  1637. // };
  1638. // extern "C" {
  1639. // class X {
  1640. // void mf(); // the name of the function mf and the member
  1641. // // function's type have C++ language linkage
  1642. // void mf2(void(*)()); // the name of the function mf2 has C++ language
  1643. // // linkage; the parameter has type pointer to
  1644. // // C function
  1645. // };
  1646. // }
  1647. public void test7_5s4b() throws Exception {
  1648. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1649. }
  1650. // namespace A {
  1651. // extern "C" int f();
  1652. // extern "C" int g() { return 1; }
  1653. // extern "C" int h();
  1654. // }
  1655. // namespace B {
  1656. // extern "C" int f(); // A::f and B::f refer
  1657. // // to the same function
  1658. // extern "C" int g() { return 1; } // illformed,
  1659. // // the function g
  1660. // // with C language linkage
  1661. // // has two definitions
  1662. // }
  1663. // int A::f() { return 98; } // definition for the function f
  1664. // // with C language linkage
  1665. // extern "C" int h() { return 97; }
  1666. // // definition for the function h
  1667. // // with C language linkage
  1668. // // A::h and ::h refer to the same function
  1669. public void test7_5s6() throws Exception {
  1670. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1671. }
  1672. // extern "C" double f();
  1673. // static double f(); // error
  1674. public void test7_5s7a() throws Exception {
  1675. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1676. }
  1677. // extern "C" int i; // declaration
  1678. // extern "C" {
  1679. // int i; // definition
  1680. // }
  1681. public void test7_5s7b() throws Exception {
  1682. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1683. }
  1684. // extern "C" static void f(); // error
  1685. public void test7_5s7c() throws Exception {
  1686. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1687. }
  1688. // int i;
  1689. // int *pi;
  1690. // int *p[3];
  1691. // int (*p3i)[3];
  1692. // int *f();
  1693. // int (*pf)(double);
  1694. public void test8_1s1() throws Exception {
  1695. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1696. }
  1697. // struct S {
  1698. // S(int);
  1699. // };
  1700. // void foo(double a)
  1701. // {
  1702. // S w(int(a)); // function declaration
  1703. // S x(int()); // function declaration
  1704. // S y((int)a); // object declaration
  1705. // S z = int(a); // object declaration
  1706. // }
  1707. public void test8_2s1() throws Exception {
  1708. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1709. }
  1710. // template <class T>
  1711. // struct S {
  1712. // T *p;
  1713. // };
  1714. // S<int()> x; // typeid
  1715. // S<int(1)> y; // expression (illformed)
  1716. public void test8_2s4() throws Exception {
  1717. IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 1);
  1718. CPPNameCollector col = new CPPNameCollector();
  1719. tu.accept(col);
  1720. assertInstance(col.getName(4), ICPPASTTemplateId.class);
  1721. assertInstance(((ICPPASTTemplateId)col.getName(4)).getTemplateArguments()[0], IASTTypeId.class);
  1722. final IASTName S_int_1 = col.getName(7);
  1723. assertInstance(S_int_1, ICPPASTTemplateId.class);
  1724. assertInstance(((ICPPASTTemplateId)S_int_1).getTemplateArguments()[0], IASTExpression.class);
  1725. assertInstance(S_int_1.getBinding(), IProblemBinding.class);
  1726. }
  1727. // void foo()
  1728. // {
  1729. // sizeof(int(1)); // expression
  1730. // // sizeof(int()); // typeid (illformed)
  1731. // }
  1732. public void test8_2s5() throws Exception {
  1733. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1734. }
  1735. // void foo()
  1736. // {
  1737. // (int(1)); //expression
  1738. // // (int())1; //typeid (illformed)
  1739. // }
  1740. public void test8_2s6() throws Exception {
  1741. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1742. }
  1743. // class C { };
  1744. // void f(int(C)) { } // void f(int (*fp)(C c)) { }
  1745. // // not: void f(int C);
  1746. // int g(C);
  1747. // void foo() {
  1748. // f(1); //error: cannot convert 1 to function pointer
  1749. // f(g); //OK
  1750. // }
  1751. public void test8_2s7a() throws Exception { // TODO raised bug 90633
  1752. final String code = getAboveComment();
  1753. parse(code, ParserLanguage.CPP, true, 1);
  1754. BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
  1755. IFunction f= ba.assertNonProblem("f", 1, IFunction.class);
  1756. isTypeEqual(f.getType(), "void (int (*)(C))");
  1757. }
  1758. // class C { };
  1759. // void h(int *(C[10])); // void h(int *(*_fp)(C _parm[10]));
  1760. // // not: void h(int *C[10]);
  1761. public void test8_2s7b() throws Exception {
  1762. final String code = getAboveComment();
  1763. parse(code, ParserLanguage.CPP, true, 0);
  1764. BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
  1765. IFunction f= ba.assertNonProblem("h", 1, IFunction.class);
  1766. isTypeEqual(f.getType(), "void (int * (*)(C *))");
  1767. }
  1768. // namespace A {
  1769. // struct B {
  1770. // void f();
  1771. // };
  1772. // void A::B::f() { } // illformed: the declarator must not be
  1773. // // qualified with A::
  1774. // }
  1775. public void test8_3s1() throws Exception {
  1776. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1777. }
  1778. // int unsigned i;
  1779. public void test8_3s4() throws Exception {
  1780. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1781. }
  1782. // const int ci = 10, *pc = &ci, *const cpc = pc, **ppc;
  1783. // int i, *p, *const cp = &i;
  1784. //
  1785. // int f() {
  1786. // i = ci;
  1787. // *cp = ci;
  1788. // pc++;
  1789. // pc = cpc;
  1790. // pc = p;
  1791. // ppc = &pc;
  1792. // }
  1793. public void test8_3_1s2a() throws Exception {
  1794. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1795. }
  1796. // const int ci = 10, *pc = &ci, *const cpc = pc, **ppc;
  1797. // int i, *p, *const cp = &i;
  1798. // int f() {
  1799. // ci = 1; // error
  1800. // ci++; //error
  1801. // *pc = 2; // error
  1802. // cp = &ci; // error
  1803. // cpc++; //error
  1804. // p = pc; // error
  1805. // ppc = &p; // error
  1806. // }
  1807. public void test8_3_1s2b() throws Exception {
  1808. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1809. }
  1810. // const int ci = 10, *pc = &ci, *const cpc = pc, **ppc;
  1811. // int i, *p, *const cp = &i;
  1812. // int f() {
  1813. // *ppc = &ci; // OK, but would make p point to ci ...
  1814. // *p = 5; // clobber ci
  1815. // }
  1816. public void test8_3_1s2c() throws Exception {
  1817. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1818. }
  1819. // typedef int& A;
  1820. // const A aref = 3; // illformed;
  1821. // // nonconst reference initialized with rvalue
  1822. public void test8_3_2s1() throws Exception {
  1823. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1824. }
  1825. // void f(double& a) { a += 3.14; }
  1826. // void foo1() {
  1827. // double d = 0;
  1828. // f(d);
  1829. // }
  1830. //
  1831. // int v[20];
  1832. // int& g(int i) { return v[i]; }
  1833. // void foo2() {
  1834. // g(3) = 7;
  1835. // }
  1836. //
  1837. // struct link {
  1838. // link* next;
  1839. // };
  1840. // link* first;
  1841. // void h(link*& p) // p is a reference to pointer
  1842. // {
  1843. // p->next = first;
  1844. // first = p;
  1845. // p = 0;
  1846. // }
  1847. // void k()
  1848. // {
  1849. // link* q = new link;
  1850. // h(q);
  1851. // }
  1852. public void test8_3_2s3() throws Exception {
  1853. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1854. }
  1855. // class X {
  1856. // public:
  1857. // void f(int);
  1858. // int a;
  1859. // };
  1860. // class Y;
  1861. //
  1862. // void f() {
  1863. // int X::* pmi = &X::a;
  1864. // void (X::* pmf)(int) = &X::f;
  1865. // double X::* pmd;
  1866. // char Y::* pmc;
  1867. // X obj;
  1868. // //...
  1869. // obj.*pmi = 7; // assign 7 to an integer
  1870. // // member of obj
  1871. // (obj.*pmf)(7); //call a function member of obj
  1872. // // with the argument 7
  1873. // }
  1874. public void test8_3_3s2() throws Exception {
  1875. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1876. }
  1877. // typedef int A[5], AA[2][3];
  1878. // typedef const A CA; // type is ''array of 5 const int''
  1879. // typedef const AA CAA; // type is ''array of 2 array of 3 const int''
  1880. public void test8_3_4s1() throws Exception {
  1881. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1882. }
  1883. // float fa[17], *afp[17];
  1884. // static int x3d[3][5][7];
  1885. public void test8_3_4s4() throws Exception {
  1886. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1887. }
  1888. // int x[3][5];
  1889. public void test8_3_4s8() throws Exception {
  1890. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1891. }
  1892. // int printf(const char*, ...);
  1893. // int f() {
  1894. // int a=1, b=0;
  1895. // printf("hello world");
  1896. // printf("a=%d b=%d", a, b);
  1897. // }
  1898. public void test8_3_5s2() throws Exception {
  1899. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1900. }
  1901. // typedef void F();
  1902. // struct S {
  1903. // const F f; // illformed:
  1904. // // not equivalent to: void f() const;
  1905. // };
  1906. public void test8_3_5s4() throws Exception {
  1907. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1908. }
  1909. // #define FILE int
  1910. // int fseek(FILE*, long, int);
  1911. public void test8_3_5s5() throws Exception {
  1912. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1913. }
  1914. // typedef void F();
  1915. // F fv; // OK: equivalent to void fv();
  1916. // // F fv { } // illformed
  1917. // void fv() { } // OK: definition of fv
  1918. public void test8_3_5s7a() throws Exception {
  1919. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1920. }
  1921. // typedef int FIC(int) const;
  1922. // FIC f; // illformed:
  1923. // //does not declare a member function
  1924. // struct S {
  1925. // FIC f; // OK
  1926. // };
  1927. // FIC S::*pm = &S::f; // OK
  1928. public void test8_3_5s7b() throws Exception {
  1929. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1930. }
  1931. // int i,
  1932. // *pi,
  1933. // f(),
  1934. // *fpi(int),
  1935. // (*pif)(const char*, const char*),
  1936. // (*fpif(int))(int);
  1937. public void test8_3_5s9a() throws Exception {
  1938. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1939. }
  1940. // typedef int IFUNC(int);
  1941. // IFUNC* fpif(int);
  1942. public void test8_3_5s9b() throws Exception {
  1943. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1944. }
  1945. // void point(int = 3, int = 4);
  1946. // void f() {
  1947. // point(1,2); point(1); point();
  1948. // }
  1949. public void test8_3_6s2() throws Exception {
  1950. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1951. }
  1952. // void f(int, int);
  1953. // void f(int, int = 7);
  1954. // void h()
  1955. // {
  1956. // f(3); //OK, calls f(3, 7)
  1957. // void f(int = 1, int); // error: does not use default
  1958. // // from surrounding scope
  1959. // }
  1960. // void m()
  1961. // {
  1962. // void f(int, int); // has no defaults
  1963. // f(4); //error: wrong number of arguments
  1964. // void f(int, int = 5); // OK
  1965. // f(4); //OK, calls f(4, 5);
  1966. // void f(int, int = 5); // error: cannot redefine, even to
  1967. // // same value
  1968. // }
  1969. // void n()
  1970. // {
  1971. // f(6); //OK, calls f(6, 7)
  1972. // }
  1973. public void test8_3_6s4() throws Exception {
  1974. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  1975. }
  1976. // int a = 1;
  1977. // int f(int);
  1978. // int g(int x = f(a)); // default argument: f(::a)
  1979. // void h() {
  1980. // a = 2;
  1981. // {
  1982. // int a = 3;
  1983. // g(); // g(f(::a))
  1984. // }
  1985. // }
  1986. public void test8_3_6s5() throws Exception {
  1987. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1988. }
  1989. // class C {
  1990. // void f(int i = 3);
  1991. // void g(int i, int j = 99);
  1992. // };
  1993. // void C::f(int i = 3) // error: default argument already
  1994. // { } // specified in class scope
  1995. // void C::g(int i = 88, int j) // in this translation unit,
  1996. // { }
  1997. public void test8_3_6s6() throws Exception {
  1998. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  1999. }
  2000. // void f()
  2001. // {
  2002. // int i;
  2003. // extern void g(int x = i); // error
  2004. // // ...
  2005. // }
  2006. public void test8_3_6s7() throws Exception {
  2007. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2008. }
  2009. // class A {
  2010. // void f(A* p = this) { } // error
  2011. // };
  2012. public void test8_3_6s8() throws Exception {
  2013. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2014. }
  2015. // int a;
  2016. // int f(int a, int b = a); // error: parameter a
  2017. // // used as default argument
  2018. // typedef int I;
  2019. // int g(float I, int b = I(2)); // error: parameter I found
  2020. // int h(int a, int b = sizeof(a)); // error, parameter a used
  2021. public void test8_3_6s9a() throws Exception {
  2022. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2023. }
  2024. // int b;
  2025. // class X {
  2026. // int a;
  2027. // int mem1(int i = a); // error: nonstatic member a
  2028. // // used as default argument
  2029. // int mem2(int i = b); // OK; use X::b
  2030. // static int b;
  2031. // };
  2032. public void test8_3_6s9b() throws Exception {
  2033. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2034. }
  2035. // int f(int = 0);
  2036. // void h()
  2037. // {
  2038. // int j = f(1);
  2039. // int k = f(); // OK, means f(0)
  2040. // }
  2041. // int (*p1)(int) = &f;
  2042. // int (*p2)() = &f; // error: type mismatch
  2043. public void test8_3_6s9c() throws Exception {
  2044. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2045. }
  2046. // struct A {
  2047. // virtual void f(int a = 7);
  2048. // };
  2049. // struct B : public A {
  2050. // void f(int a);
  2051. // };
  2052. // void m()
  2053. // {
  2054. // B* pb = new B;
  2055. // A* pa = pb;
  2056. // pa->f(); //OK, calls pa->B::f(7)
  2057. // pb->f(); //error: wrong number of arguments for B::f()
  2058. // }
  2059. public void test8_3_6s10() throws Exception {
  2060. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2061. }
  2062. // int max(int a, int b, int c)
  2063. // {
  2064. // int m = (a > b) ? a : b;
  2065. // return (m > c) ? m : c;
  2066. // }
  2067. public void test8_4s2() throws Exception {
  2068. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2069. }
  2070. // int a;
  2071. // struct X {
  2072. // static int a;
  2073. // static int b;
  2074. // };
  2075. // int X::a = 1;
  2076. // int X::b = a; // X::b = X::a
  2077. public void test8_5s10() throws Exception {
  2078. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2079. }
  2080. // struct A {
  2081. // int x;
  2082. // struct B {
  2083. // int i;
  2084. // int j;
  2085. // } b;
  2086. // } a = { 1, { 2, 3 } };
  2087. public void test8_5_1s2() throws Exception {
  2088. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2089. }
  2090. // int x[] = { 1, 3, 5 };
  2091. public void test8_5_1s4() throws Exception {
  2092. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2093. }
  2094. // struct A {
  2095. // int i;
  2096. // static int s;
  2097. // int j;
  2098. // } a = { 1, 2 };
  2099. public void test8_5_1s5() throws Exception {
  2100. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2101. }
  2102. // char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
  2103. public void test8_5_1s6() throws Exception {
  2104. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2105. }
  2106. // struct S { int a; char* b; int c; };
  2107. // S ss = { 1, "asdf" };
  2108. public void test8_5_1s7() throws Exception {
  2109. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2110. }
  2111. // struct S { };
  2112. // struct A {
  2113. // S s;
  2114. // int i;
  2115. // } a = { { } , 3 };
  2116. public void test8_5_1s8() throws Exception {
  2117. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2118. }
  2119. // int x[2][2] = { 3, 1, 4, 2 };
  2120. // float y[4][3] = {
  2121. // { 1 }, { 2 }, { 3 }, { 4 }
  2122. // };
  2123. public void test8_5_1s10() throws Exception {
  2124. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2125. }
  2126. // float y[4][3] = {
  2127. // { 1, 3, 5 },
  2128. // { 2, 4, 6 },
  2129. // { 3, 5, 7 },
  2130. // };
  2131. public void test8_5_1s11a() throws Exception {
  2132. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2133. }
  2134. // float y[4][3] = {
  2135. // 1, 3, 5, 2, 4, 6, 3, 5, 7
  2136. // };
  2137. public void test8_5_1s11b() throws Exception {
  2138. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2139. }
  2140. // struct A {
  2141. // int i;
  2142. // operator int();
  2143. // };
  2144. // struct B {
  2145. // A a1, a2;
  2146. // int z;
  2147. // };
  2148. // A a;
  2149. // B b = { 4, a, a };
  2150. public void test8_5_1s12() throws Exception {
  2151. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2152. }
  2153. // union u { int a; char* b; };
  2154. // u a = { 1 };
  2155. // u b = a;
  2156. // u c = 1; // error
  2157. // u d = { 0, "asdf" }; // error
  2158. // u e = { "asdf" }; // error
  2159. public void test8_5_1s15() throws Exception {
  2160. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2161. }
  2162. // char msg[] = "Syntax error on line %s";
  2163. public void test8_5_2s1() throws Exception {
  2164. // raised bug 90647
  2165. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2166. }
  2167. // char cv[4] = "asdf"; // error
  2168. public void test8_5_2s2() throws Exception {
  2169. // we do not check the size of an array, which is ok.
  2170. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2171. }
  2172. // int& r1; // error: initializer missing
  2173. // extern int& r2; // OK
  2174. public void test8_5_3s2() throws Exception {
  2175. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2176. }
  2177. // double d = 2.0;
  2178. // double& rd = d; // rd refers to d
  2179. // const double& rcd = d; // rcd refers to d
  2180. // struct A { };
  2181. // struct B : public A { } b;
  2182. // A& ra = b; // ra refers to A subobject in b
  2183. // const A& rca = b; // rca refers to A subobject in b
  2184. public void test8_5_3s5a() throws Exception {
  2185. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2186. }
  2187. // double& rd2 = 2.0; // error: not an lvalue and reference not const
  2188. // int i = 2;
  2189. // double& rd3 = i; // error: type mismatch and reference not const
  2190. public void test8_5_3s5b() throws Exception {
  2191. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2192. }
  2193. // struct A { };
  2194. // struct B : public A { } b;
  2195. // extern B f();
  2196. // const A& rca = f(); // Either bound to the A subobject of the B rvalue,
  2197. // // or the entire B object is copied and the reference
  2198. // // is bound to the A subobject of the copy
  2199. public void test8_5_3s5c() throws Exception {
  2200. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2201. }
  2202. // const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0
  2203. // const volatile int cvi = 1;
  2204. // const int& r = cvi; // error: type qualifiers dropped
  2205. public void test8_5_3s5d() throws Exception {
  2206. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2207. }
  2208. // struct X { int a; };
  2209. // struct Y { int a; };
  2210. // X a1;
  2211. // Y a2;
  2212. // int a3;
  2213. // void test() {
  2214. // a1 = a2; // error: Y assigned to X
  2215. // a1 = a3; // error: int assigned to X
  2216. // }
  2217. // int f(X);
  2218. // int f(Y);
  2219. // struct S { int a; };
  2220. // struct S { int a; }; // error, double definition
  2221. public void test9_1s1() throws Exception {
  2222. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2223. }
  2224. // struct stat {
  2225. // // ...
  2226. // };
  2227. // stat gstat; // use plain stat to
  2228. // // define variable
  2229. // int stat(struct stat*); // redeclare stat as function
  2230. // void f()
  2231. // {
  2232. // struct stat* ps; // struct prefix needed
  2233. // // to name struct stat
  2234. // // ...
  2235. // stat(ps); //call stat()
  2236. // // ...
  2237. // }
  2238. public void test9_1s2a() throws Exception {
  2239. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2240. }
  2241. // struct s { int a; };
  2242. // void g()
  2243. // {
  2244. // struct s; // hide global struct s
  2245. // // with a local declaration
  2246. // s* p; // refer to local struct s
  2247. // struct s { char* p; }; // define local struct s
  2248. // struct s; // redeclaration, has no effect
  2249. // }
  2250. public void test9_1s2b() throws Exception {
  2251. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2252. }
  2253. // class Vector;
  2254. // class Matrix {
  2255. // // ...
  2256. // friend Vector operator*(Matrix&, Vector&);
  2257. // };
  2258. // class Vector {
  2259. // // ...
  2260. // friend Vector operator*(Matrix&, Vector&);
  2261. // };
  2262. public void test9_1s2c() throws Exception {
  2263. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2264. }
  2265. // struct s { int a; };
  2266. // void g(int s)
  2267. // {
  2268. // struct s* p = new struct s; // global s
  2269. // p->a = s; // local s
  2270. // }
  2271. public void test9_1s3() throws Exception {
  2272. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2273. }
  2274. // class A * A;
  2275. public void test9_1s4() throws Exception {
  2276. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2277. }
  2278. // struct tnode {
  2279. // char tword[20];
  2280. // int count;
  2281. // tnode *left;
  2282. // tnode *right;
  2283. // };
  2284. // tnode s, *sp;
  2285. public void test9_2s11() throws Exception {
  2286. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2287. }
  2288. // struct X {
  2289. // typedef int T;
  2290. // static T count;
  2291. // void f(T);
  2292. // };
  2293. // void X::f(T t = count) { }
  2294. public void test9_3s5() throws Exception {
  2295. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2296. }
  2297. // typedef void fv(void);
  2298. // typedef void fvc(void) const;
  2299. // struct S {
  2300. // fv memfunc1; // equivalent to: void memfunc1(void);
  2301. // void memfunc2();
  2302. // fvc memfunc3; // equivalent to: void memfunc3(void) const;
  2303. // };
  2304. // fv S::* pmfv1 = &S::memfunc1;
  2305. // fv S::* pmfv2 = &S::memfunc2;
  2306. // fvc S::* pmfv3 = &S::memfunc3;
  2307. public void test9_3s9() throws Exception {
  2308. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2309. }
  2310. // struct tnode {
  2311. // char tword[20];
  2312. // int count;
  2313. // tnode *left;
  2314. // tnode *right;
  2315. // void set(char*, tnode* l, tnode* r);
  2316. // };
  2317. // void tnode::set(char* w, tnode* l, tnode* r)
  2318. // {
  2319. // count = strlen(w)+1;
  2320. // if (sizeof(tword)<=count)
  2321. // perror("tnode string too long");
  2322. // strcpy(tword,w);
  2323. // left = l;
  2324. // right = r;
  2325. // }
  2326. // void f(tnode n1, tnode n2)
  2327. // {
  2328. // n1.set("abc",&n2,0);
  2329. // n2.set("def",0,0);
  2330. // }
  2331. public void test9_3_1s2() throws Exception {
  2332. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2333. }
  2334. // struct X {
  2335. // void g() const;
  2336. // void h() const volatile;
  2337. // };
  2338. public void test9_3_1s3() throws Exception {
  2339. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2340. }
  2341. // struct s {
  2342. // int a;
  2343. // int f() const;
  2344. // int g() { return a++; }
  2345. // int h() const { return a++; } // error
  2346. // };
  2347. // int s::f() const { return a; }
  2348. public void test9_3_2s2() throws Exception {
  2349. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2350. }
  2351. // struct s {
  2352. // int a;
  2353. // int f() const;
  2354. // int g() { return a++; }
  2355. // };
  2356. // int s::f() const { return a; }
  2357. //
  2358. // void k(s& x, const s& y)
  2359. // {
  2360. // x.f();
  2361. // x.g();
  2362. // y.f();
  2363. // y.g(); //error
  2364. // }
  2365. public void test9_3_2s4() throws Exception {
  2366. String[] problems= {"g"};
  2367. final String code = getAboveComment();
  2368. IASTTranslationUnit tu= parse(code, ParserLanguage.CPP, problems);
  2369. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  2370. bh.assertNonProblem("g();", 1);
  2371. bh.assertProblem("g(); //error", 1);
  2372. }
  2373. // class process {
  2374. // public:
  2375. // static void reschedule();
  2376. // };
  2377. // process& g();
  2378. // void f()
  2379. // {
  2380. // process::reschedule(); // OK: no object necessary
  2381. // g().reschedule(); // g() is called
  2382. // }
  2383. public void test9_4s2a() throws Exception {
  2384. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2385. }
  2386. // int g();
  2387. // struct X {
  2388. // static int g();
  2389. // };
  2390. // struct Y : X {
  2391. // static int i;
  2392. // };
  2393. // int Y::i = g(); // equivalent to Y::g();
  2394. public void test9_4s2b() throws Exception {
  2395. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2396. }
  2397. // class process {
  2398. // static process* run_chain;
  2399. // static process* running;
  2400. // };
  2401. // process* process::running = get_main();
  2402. // process* process::run_chain = running;
  2403. public void test9_4_2s2() throws Exception {
  2404. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2405. }
  2406. // void f()
  2407. // {
  2408. // union { int a; char* p; };
  2409. // a = 1;
  2410. // // ...
  2411. // p = "Jennifer";
  2412. // // ...
  2413. // }
  2414. public void test9_5s2() throws Exception {
  2415. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2416. }
  2417. // int foo() {
  2418. // union { int aa; char* p; } obj, *ptr = &obj;
  2419. // aa = 1; // error
  2420. // ptr->aa = 1; // OK
  2421. // }
  2422. public void test9_5s4() throws Exception {
  2423. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2424. }
  2425. // enum BOOL { f=0, t=1 };
  2426. // struct A {
  2427. // BOOL b:1;
  2428. // };
  2429. // A a;
  2430. // void f() {
  2431. // a.b = t;
  2432. // if (a.b == t) // shall yield true
  2433. // { }
  2434. // }
  2435. public void test9_6s4() throws Exception {
  2436. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2437. }
  2438. // int x;
  2439. // int y;
  2440. // class enclose {
  2441. // public:
  2442. // int x;
  2443. // static int s;
  2444. // class inner {
  2445. // void f(int i)
  2446. // {
  2447. // int a = sizeof(x); // error: refers to enclose::x
  2448. // x = i; // error: assign to enclose::x
  2449. // s = i; // OK: assign to enclose::s
  2450. // ::x = i; // OK: assign to global x
  2451. // y = i; // OK: assign to global y
  2452. // }
  2453. // void g(enclose* p, int i)
  2454. // {
  2455. // p>
  2456. // x = i; // OK: assign to enclose::x
  2457. // }
  2458. // };
  2459. // };
  2460. // inner* p = 0; // error: inner not in scope
  2461. public void test9_7s1() throws Exception {
  2462. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2463. }
  2464. // class enclose {
  2465. // public:
  2466. // class inner {
  2467. // static int x;
  2468. // void f(int i);
  2469. // };
  2470. // };
  2471. // int enclose::inner::x = 1;
  2472. // void enclose::inner::f(int i) { }
  2473. public void test9_7s2() throws Exception {
  2474. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2475. }
  2476. // class E {
  2477. // class I1; // forward declaration of nested class
  2478. // class I2;
  2479. // class I1 {}; // definition of nested class
  2480. // };
  2481. // class E::I2 {}; // definition of nested class
  2482. public void test9_7s3() throws Exception {
  2483. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2484. }
  2485. // int x;
  2486. // void f()
  2487. // {
  2488. // static int s ;
  2489. // int x;
  2490. // extern int g();
  2491. // struct local {
  2492. // int g() { return x; } // error: x is auto
  2493. // int h() { return s; } // OK
  2494. // int k() { return ::x; } // OK
  2495. // int l() { return g(); } // OK
  2496. // };
  2497. // // ...
  2498. // }
  2499. // local* p = 0; // error: local not in scope
  2500. public void test9_8s1() throws Exception {
  2501. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2502. }
  2503. // class X {
  2504. // public:
  2505. // typedef int I;
  2506. // class Y { /* ... */ };
  2507. // I a;
  2508. // };
  2509. // I b; // error
  2510. // Y c; // error
  2511. // X::Y d; // OK
  2512. // X::I e; // OK
  2513. public void test9_9s1() throws Exception {
  2514. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2515. }
  2516. // class Base {
  2517. // public:
  2518. // int a, b, c;
  2519. // };
  2520. // class Derived : public Base {
  2521. // public:
  2522. // int b;
  2523. // };
  2524. // class Derived2 : public Derived {
  2525. // public:
  2526. // int c;
  2527. // };
  2528. public void test10s2() throws Exception {
  2529. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2530. }
  2531. // class A { };
  2532. // class B { };
  2533. // class C { };
  2534. // class D : public A, public B, public C { };
  2535. public void test10_1s1() throws Exception {
  2536. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2537. }
  2538. // class X { };
  2539. // class Y : public X, public X { }; // illformed
  2540. public void test10_1s3a() throws Exception {
  2541. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2542. }
  2543. // class L { public: int next; };
  2544. // class A : public L { };
  2545. // class B : public L { };
  2546. // class C : public A, public B { void f(); }; // wellformed
  2547. // class D : public A, public L { void f(); }; // wellformed
  2548. //
  2549. public void test10_1s3b() throws Exception {
  2550. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2551. }
  2552. // class A {
  2553. // public:
  2554. // int a;
  2555. // int (*b)();
  2556. // int f();
  2557. // int f(int);
  2558. // int g();
  2559. // };
  2560. // class B {
  2561. // int a;
  2562. // int b();
  2563. // public:
  2564. // int f();
  2565. // int g;
  2566. // int h();
  2567. // int h(int);
  2568. // };
  2569. // class C : public A, public B {};
  2570. // void g(C* pc)
  2571. // {
  2572. // pc->a = 1; // error: ambiguous: A::a or B::a
  2573. // pc->b(); //error: ambiguous: A::b or B::b
  2574. // pc->f(); //error: ambiguous: A::f or B::f
  2575. // pc->f(1); //error: ambiguous: A::f or B::f
  2576. // pc->g(); //error: ambiguous: A::g or B::g
  2577. // pc->g = 1; // error: ambiguous: A::g or B::g
  2578. // pc->h(); //OK
  2579. // pc->h(1); //OK
  2580. // }
  2581. public void test10_2s3a() throws Exception {
  2582. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2583. }
  2584. // struct U { static int i; };
  2585. // struct V : U { };
  2586. // struct W : U { using U::i; };
  2587. // struct X : V, W { void foo(); };
  2588. // void X::foo() {
  2589. // i; //finds U::i in two ways: as W::i and U::i in V
  2590. // // no ambiguity because U::i is static
  2591. // }
  2592. public void test10_2s3b() throws Exception {
  2593. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2594. }
  2595. // class A {
  2596. // public:
  2597. // int f();
  2598. // };
  2599. // class B {
  2600. // public:
  2601. // int f();
  2602. // };
  2603. // class C : public A, public B {
  2604. // int f() { return A::f() + B::f(); }
  2605. // };
  2606. public void test10_2s4() throws Exception {
  2607. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2608. }
  2609. // class V { public: int v; };
  2610. // class A {
  2611. // public:
  2612. // int a;
  2613. // static int s;
  2614. // enum { e };
  2615. // };
  2616. // class B : public A, public virtual V {};
  2617. // class C : public A, public virtual V {};
  2618. // class D : public B, public C { };
  2619. // void f(D* pd)
  2620. // {
  2621. // pd->v++; //OK: only one v (virtual)
  2622. // pd->s++; //OK: only one s (static)
  2623. // int i = pd>
  2624. // e; // OK: only one e (enumerator)
  2625. // pd->a++; //error, ambiguous: two as in D
  2626. // }
  2627. public void test10_2s5() throws Exception {
  2628. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2629. }
  2630. // class V { public: int f(); int x; };
  2631. // class W { public: int g(); int y; };
  2632. // class B : public virtual V, public W
  2633. // {
  2634. // public:
  2635. // int f(); int x;
  2636. // int g(); int y;
  2637. // };
  2638. // class C : public virtual V, public W { };
  2639. // class D : public B, public C { void glorp(); };
  2640. public void test10_2s6() throws Exception {
  2641. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2642. }
  2643. // class V { };
  2644. // class A { };
  2645. // class B : public A, public virtual V { };
  2646. // class C : public A, public virtual V { };
  2647. // class D : public B, public C { };
  2648. // void g()
  2649. // {
  2650. // D d;
  2651. // B* pb = &d;
  2652. // A* pa = &d; // error, ambiguous: C's A or B's A?
  2653. // V* pv = &d; // OK: only one V subobject
  2654. // }
  2655. public void test10_2s7() throws Exception {
  2656. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2657. }
  2658. // struct A {
  2659. // virtual void f();
  2660. // };
  2661. // struct B : virtual A {
  2662. // virtual void f();
  2663. // };
  2664. // struct C : B , virtual A {
  2665. // using A::f;
  2666. // };
  2667. // void foo() {
  2668. // C c;
  2669. // c.f(); //calls B::f, the final overrider
  2670. // c.C::f(); //calls A::f because of the usingdeclaration
  2671. // }
  2672. public void test10_3s2() throws Exception {
  2673. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2674. }
  2675. // class B {};
  2676. // class D : private B { friend class Derived; };
  2677. // struct Base {
  2678. // virtual void vf1();
  2679. // virtual void vf2();
  2680. // virtual void vf3();
  2681. // virtual B* vf4();
  2682. // virtual B* vf5();
  2683. // void f();
  2684. // };
  2685. // struct No_good : public Base {
  2686. // D* vf4(); // error: B (base class of D) inaccessible
  2687. // };
  2688. // class A;
  2689. // struct Derived : public Base {
  2690. // void vf1(); // virtual and overrides Base::vf1()
  2691. // void vf2(int); // not virtual, hides Base::vf2()
  2692. // char vf3(); // error: invalid difference in return type only
  2693. // D* vf4(); // OK: returns pointer to derived class
  2694. // A* vf5(); // error: returns pointer to incomplete class
  2695. // void f();
  2696. // };
  2697. // void g()
  2698. // {
  2699. // Derived d;
  2700. // Base* bp = &d; // standard conversion:
  2701. // // Derived* to Base*
  2702. // bp->vf1(); //calls Derived::vf1()
  2703. // bp->vf2(); //calls Base::vf2()
  2704. // bp->f(); //calls Base::f() (not virtual)
  2705. // B* p = bp->vf4(); // calls Derived::pf() and converts the
  2706. // // result to B*
  2707. // Derived* dp = &d;
  2708. // D* q = dp->vf4(); // calls Derived::pf() and does not
  2709. // // convert the result to B*
  2710. // dp->vf2(); //illformed: argument mismatch
  2711. // }
  2712. public void test10_3s5() throws Exception {
  2713. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2714. }
  2715. // struct A {
  2716. // virtual void f();
  2717. // };
  2718. // struct B1 : A { // note nonvirtual derivation
  2719. // void f();
  2720. // };
  2721. // struct B2 : A {
  2722. // void f();
  2723. // };
  2724. // struct D : B1, B2 { // D has two separate A subobjects
  2725. // };
  2726. // void foo()
  2727. // {
  2728. // D d;
  2729. // // A* ap = &d; // would be illformed:ambiguous
  2730. // B1* b1p = &d;
  2731. // A* ap = b1p;
  2732. // D* dp = &d;
  2733. // ap->f(); //calls D::B1::f
  2734. // dp->f(); //illformed: ambiguous
  2735. // }
  2736. public void test10_3s9() throws Exception {
  2737. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2738. }
  2739. // struct A {
  2740. // virtual void f();
  2741. // };
  2742. // struct VB1 : virtual A { // note virtual derivation
  2743. // void f();
  2744. // };
  2745. // struct VB2 : virtual A {
  2746. // void f();
  2747. // };
  2748. // struct Error : VB1, VB2 { // illformed
  2749. // };
  2750. // struct Okay : VB1, VB2 {
  2751. // void f();
  2752. // };
  2753. public void test10_3s10() throws Exception {
  2754. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2755. }
  2756. // struct VB1a : virtual A { // does not declare f
  2757. // };
  2758. // struct Da : VB1a, VB2 {
  2759. // };
  2760. // void foe()
  2761. // {
  2762. // VB1a* vb1ap = new Da;
  2763. // vb1ap->f(); //calls VB2::f
  2764. // }
  2765. public void test10_3s11() throws Exception {
  2766. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2767. }
  2768. // class B { public: virtual void f(); };
  2769. // class D : public B { public: void f(); };
  2770. // void D::f() { B::f(); }
  2771. public void test10_3s12() throws Exception {
  2772. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2773. }
  2774. // class point { };
  2775. // class shape { // abstract class
  2776. // point center;
  2777. // // ...
  2778. // public:
  2779. // point where() { return center; }
  2780. // void move(point p) { center=p; draw(); }
  2781. // virtual void rotate(int) = 0; // pure virtual
  2782. // virtual void draw() = 0; // pure virtual
  2783. // // ...
  2784. // };
  2785. public void test10_4s2a() throws Exception {
  2786. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2787. }
  2788. // Not legal C++
  2789. // // public void test10_4s2b() throws Exception {
  2790. // StringBuffer buffer = new StringBuffer();
  2791. // buffer.append("struct C {\n"); //$NON-NLS-1$
  2792. // buffer.append("virtual void f() { }=0; // illformed\n"); //$NON-NLS-1$
  2793. // buffer.append("};\n"); //$NON-NLS-1$
  2794. // parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2795. // }
  2796. // shape x; // error: object of abstract class
  2797. // shape* p; // OK
  2798. // shape f(); // error
  2799. // void g(shape); // error
  2800. // shape& h(shape&); // OK
  2801. public void test10_4s3() throws Exception {
  2802. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2803. }
  2804. // class ab_circle : public shape {
  2805. // int radius;
  2806. // public:
  2807. // void rotate(int) {}
  2808. // // ab_circle::draw() is a pure virtual
  2809. // };
  2810. public void test10_4s4a() throws Exception {
  2811. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2812. }
  2813. // class circle : public shape {
  2814. // int radius;
  2815. // public:
  2816. // void rotate(int) {}
  2817. // void draw(); // a definition is required somewhere
  2818. // };
  2819. public void test10_4s4b() throws Exception {
  2820. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2821. }
  2822. // class X {
  2823. // int a; // X::a is private by default
  2824. // };
  2825. // struct S {
  2826. // int a; // S::a is public by default
  2827. // };
  2828. public void test11s2() throws Exception {
  2829. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2830. }
  2831. // class A
  2832. // {
  2833. // class B { };
  2834. // public:
  2835. // typedef B BB;
  2836. // };
  2837. // void f()
  2838. // {
  2839. // A::BB x; // OK, typedef name A::BB is public
  2840. // A::B y; // access error, A::B is private
  2841. // }
  2842. public void test11s3() throws Exception {
  2843. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2844. }
  2845. // class A {
  2846. // typedef int I; // private member
  2847. // I f();
  2848. // friend I g(I);
  2849. // static I x;
  2850. // };
  2851. // A::I A::f() { return 0; }
  2852. // A::I g(A::I p = A::x);
  2853. // A::I g(A::I p) { return 0; }
  2854. // A::I A::x = 0;
  2855. public void test11s5() throws Exception {
  2856. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2857. }
  2858. // class D {
  2859. // class E {
  2860. // static int m;
  2861. // };
  2862. // };
  2863. // int D::E::m = 1; // OK, no access error on private E
  2864. public void test11s6() throws Exception {
  2865. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2866. }
  2867. // class X {
  2868. // int a; // X::a is private by default: class used
  2869. // public:
  2870. // int b; // X::b is public
  2871. // int c; // X::c is public
  2872. // };
  2873. public void test11_1s1a() throws Exception {
  2874. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2875. }
  2876. // struct S {
  2877. // int a; // S::a is public by default: struct used
  2878. // protected:
  2879. // int b; // S::b is protected
  2880. // private:
  2881. // int c; // S::c is private
  2882. // public:
  2883. // int d; // S::d is public
  2884. // };
  2885. public void test11s1b() throws Exception {
  2886. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2887. }
  2888. // struct S {
  2889. // class A;
  2890. // private:
  2891. // class A { }; // error: cannot change access
  2892. // };
  2893. public void test11_1s3() throws Exception {
  2894. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2895. }
  2896. // class B { };
  2897. // class D1 : private B { };
  2898. // class D2 : public B { };
  2899. // class D3 : B { }; // B private by default
  2900. // struct D4 : public B { };
  2901. // struct D5 : private B { };
  2902. // struct D6 : B { }; // B public by default
  2903. // class D7 : protected B { };
  2904. // struct D8 : protected B { };
  2905. public void test11_2s2() throws Exception {
  2906. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2907. }
  2908. // class B {
  2909. // public:
  2910. // int mi; // nonstatic member
  2911. // static int si; // static member
  2912. // };
  2913. // class D : private B {
  2914. // };
  2915. // class DD : public D {
  2916. // void f();
  2917. // };
  2918. // void DD::f() {
  2919. // mi = 3; // error: mi is private in D
  2920. // si = 3; // error: si is private in D
  2921. // B b;
  2922. // b.mi = 3; // OK (b.mi is different from this->mi)
  2923. // b.si = 3; // OK (b.si is different from this->si)
  2924. // B::si = 3; // OK
  2925. // B* bp1 = this; // error: B is a private base class
  2926. // B* bp2 = (B*)this; // OK with cast
  2927. // bp2->mi = 3; // OK: access through a pointer to B.
  2928. // }
  2929. public void test11_2s3() throws Exception {
  2930. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2931. }
  2932. // class B;
  2933. // class A {
  2934. // private:
  2935. // int i;
  2936. // friend void f(B*);
  2937. // };
  2938. // class B : public A { };
  2939. // void f(B* p) {
  2940. // p->i = 1; // OK: B* can be implicitly cast to A*,
  2941. // // and f has access to i in A
  2942. // }
  2943. public void test11_2s4() throws Exception {
  2944. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2945. }
  2946. // class X {
  2947. // int a;
  2948. // friend void friend_set(X*, int);
  2949. // public:
  2950. // void member_set(int);
  2951. // };
  2952. // void friend_set(X* p, int i) { p->a = i; }
  2953. // void X::member_set(int i) { a = i; }
  2954. // void f()
  2955. // {
  2956. // X obj;
  2957. // friend_set(&obj,10);
  2958. // obj.member_set(10);
  2959. // }
  2960. public void test11_4s1() throws Exception {
  2961. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2962. }
  2963. // class A {
  2964. // class B { };
  2965. // friend class X;
  2966. // };
  2967. // class X : A::B { // illformed:
  2968. // //A::B cannot be accessed
  2969. // // in the baseclause for X
  2970. // A::B mx; // OK: A::B used to declare member of X
  2971. // class Y : A::B { // OK: A::B used to declare member of X
  2972. // A::B my; // illformed: A::B cannot be accessed
  2973. // // to declare members of nested class of X
  2974. // };
  2975. // };
  2976. public void test11_4s2a() throws Exception {
  2977. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2978. }
  2979. // class X {
  2980. // enum { a=100 };
  2981. // friend class Y;
  2982. // };
  2983. // class Y {
  2984. // int v[X::a]; // OK, Y is a friend of X
  2985. // };
  2986. // class Z {
  2987. // int v[X::a]; // error: X::a is private
  2988. // };
  2989. public void test11_4s2b() throws Exception {
  2990. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  2991. }
  2992. // class Y {
  2993. // friend char* X::foo(int);
  2994. // // ...
  2995. // };
  2996. public void test11_4s4() throws Exception {
  2997. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  2998. }
  2999. // class M {
  3000. // friend void f() { } // definition of global f, a friend of M,
  3001. // // not the definition of a member function
  3002. // };
  3003. public void test11_4s5() throws Exception {
  3004. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3005. }
  3006. // class A {
  3007. // friend class B;
  3008. // int a;
  3009. // };
  3010. // class B {
  3011. // friend class C;
  3012. // };
  3013. // class C {
  3014. // void f(A* p)
  3015. // {
  3016. // p->a++; //error: C is not a friend of A
  3017. // // despite being a friend of a friend
  3018. // }
  3019. // };
  3020. // class D : public B {
  3021. // void f(A* p)
  3022. // {
  3023. // p->a++; //error: D is not a friend of A
  3024. // // despite being derived from a friend
  3025. // }
  3026. // };
  3027. public void test11_4s8() throws Exception {
  3028. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3029. }
  3030. // class X;
  3031. // void a();
  3032. // void f() {
  3033. // class Y;
  3034. // extern void b();
  3035. // class A {
  3036. // friend class X; // OK, but X is a local class, not ::X
  3037. // friend class Y; // OK
  3038. // friend class Z; // OK, introduces local class Z
  3039. // friend void a(); // error, ::a is not considered
  3040. // friend void b(); // OK
  3041. // friend void c(); // error
  3042. // };
  3043. // X *px; // OK, but ::X is found
  3044. // Z *pz; // error, no Z is found
  3045. // }
  3046. public void test11_4s9() throws Exception {
  3047. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3048. }
  3049. // class B {
  3050. // protected:
  3051. // int i;
  3052. // static int j;
  3053. // };
  3054. // class D1 : public B {
  3055. // };
  3056. // class D2 : public B {
  3057. // friend void fr(B*,D1*,D2*);
  3058. // void mem(B*,D1*);
  3059. // };
  3060. // void fr(B* pb, D1* p1, D2* p2)
  3061. // {
  3062. // pb->i = 1; // illformed
  3063. // p1->i = 2; // illformed
  3064. // p2->i = 3; // OK (access through a D2)
  3065. // p2->B::i = 4; // OK (access through a D2, even though
  3066. // // naming class is B)
  3067. // int B::* pmi_B = &B::i; // illformed
  3068. // int B::* pmi_B2 = &D2::i; // OK (type of &D2::i is int B::*)
  3069. // B::j = 5; // OK (because refers to static member)
  3070. // D2::j =6; // OK (because refers to static member)
  3071. // }
  3072. // void D2::mem(B* pb, D1* p1)
  3073. // {
  3074. // pb->i = 1; // illformed
  3075. // p1->i = 2; // illformed
  3076. // i = 3; // OK (access through this)
  3077. // B::i = 4; // OK (access through this, qualification ignored)
  3078. // int B::* pmi_B = &B::i; // illformed
  3079. // int B::* pmi_B2 = &D2::i; // OK
  3080. // j = 5; // OK (because j refers to static member)
  3081. // B::j = 6; // OK (because B::j refers to static member)
  3082. // }
  3083. // void g(B* pb, D1* p1, D2* p2)
  3084. // {
  3085. // pb->i = 1; // illformed
  3086. // p1->i = 2; // illformed
  3087. // p2->i = 3; // illformed
  3088. // }
  3089. public void test11_5s1() throws Exception {
  3090. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3091. }
  3092. // class B {
  3093. // public:
  3094. // virtual int f();
  3095. // };
  3096. // class D : public B {
  3097. // private:
  3098. // int f();
  3099. // };
  3100. // void f()
  3101. // {
  3102. // D d;
  3103. // B* pb = &d;
  3104. // D* pd = &d;
  3105. // pb->f(); //OK: B::f() is public,
  3106. // // D::f() is invoked
  3107. // pd->f(); //error: D::f() is private
  3108. // }
  3109. public void test11_6s1() throws Exception {
  3110. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3111. }
  3112. // class W { public: void f(); };
  3113. // class A : private virtual W { };
  3114. // class B : public virtual W { };
  3115. // class C : public A, public B {
  3116. // void f() { W::f(); } // OK
  3117. // };
  3118. public void test11_7s1() throws Exception {
  3119. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3120. }
  3121. // class E {
  3122. // int x;
  3123. // class B { };
  3124. // class I {
  3125. // B b; // error: E::B is private
  3126. // int y;
  3127. // void f(E* p, int i)
  3128. // {
  3129. // p->x = i; // error: E::x is private
  3130. // }
  3131. // };
  3132. // int g(I* p)
  3133. // {
  3134. // return p->y; // error: I::y is private
  3135. // }
  3136. // };
  3137. public void test11_8s1() throws Exception {
  3138. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3139. }
  3140. // class C {
  3141. // class A { };
  3142. // A *p; // OK
  3143. // class B : A // OK
  3144. // {
  3145. // A *q; // OK because of injection of name A in A
  3146. // C::A *r; // error, C::A is inaccessible
  3147. // B *s; // OK because of injection of name B in B
  3148. // C::B *t; // error, C::B is inaccessible
  3149. // };
  3150. // };
  3151. public void test11_8s2() throws Exception {
  3152. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3153. }
  3154. // class C {
  3155. // public:
  3156. // C(); //declares the constructor
  3157. // };
  3158. // C::C() { } // defines the constructor
  3159. public void test12_1s1() throws Exception {
  3160. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3161. }
  3162. // struct C;
  3163. // void no_opt(C*);
  3164. // struct C {
  3165. // int c;
  3166. // C() : c(0) { no_opt(this); }
  3167. // };
  3168. // const C cobj;
  3169. // void no_opt(C* cptr) {
  3170. // int i = cobj.c * 100; // value of cobj.c is unspecified
  3171. // cptr->c = 1;
  3172. // cout << cobj.c * 100 // value of cobj.c is unspecified
  3173. // << '\
  3174. // ';
  3175. // }
  3176. public void test12_1s15() throws Exception {
  3177. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3178. }
  3179. // class X {
  3180. // // ...
  3181. // public:
  3182. // // ...
  3183. // X(int);
  3184. // X(const X&);
  3185. // ~X();
  3186. // };
  3187. // X f(X);
  3188. // void g()
  3189. // {
  3190. // X a(1);
  3191. // X b = f(X(2));
  3192. // a = f(a);
  3193. // }
  3194. public void test12_2s2() throws Exception {
  3195. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3196. }
  3197. // class C {
  3198. // // ...
  3199. // public:
  3200. // C();
  3201. // C(int);
  3202. // friend C operator+(const C&, const C&);
  3203. // ~C();
  3204. // };
  3205. // C obj1;
  3206. // const C& cr = C(16)+C(23);
  3207. // C obj2;
  3208. public void test12_2s5() throws Exception {
  3209. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3210. }
  3211. // class X {
  3212. // // ...
  3213. // public:
  3214. // operator int();
  3215. // };
  3216. // class Y {
  3217. // // ...
  3218. // public:
  3219. // operator X();
  3220. // };
  3221. // Y a;
  3222. // int b = a; // error:
  3223. // // a.operator X().operator int() not tried
  3224. // int c = X(a); // OK: a.operator X().operator int()
  3225. public void test12_3s4() throws Exception {
  3226. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3227. }
  3228. // class X {
  3229. // public:
  3230. // // ...
  3231. // operator int();
  3232. // };
  3233. // class Y : public X {
  3234. // public:
  3235. // // ...
  3236. // operator char();
  3237. // };
  3238. // void f(Y& a)
  3239. // {
  3240. // if (a) { // illformed:
  3241. // // X::operator int() or Y::operator char()
  3242. // // ...
  3243. // }
  3244. // }
  3245. public void test12_3s5() throws Exception {
  3246. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3247. }
  3248. // class X {
  3249. // // ...
  3250. // public:
  3251. // X(int);
  3252. // X(const char*, int =0);
  3253. // };
  3254. // void f(X arg)
  3255. // {
  3256. // X a = 1; // a = X(1)
  3257. // X b = "Jessie"; // b = X("Jessie",0)
  3258. // a = 2; // a = X(2)
  3259. // f(3); // f(X(3))
  3260. // }
  3261. public void test12_3_1s1() throws Exception {
  3262. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3263. }
  3264. // class Z {
  3265. // public:
  3266. // explicit Z();
  3267. // explicit Z(int);
  3268. // // ...
  3269. // };
  3270. // Z a; // OK: defaultinitialization performed
  3271. // Z a1 = 1; // error: no implicit conversion
  3272. // Z a3 = Z(1); // OK: direct initialization syntax used
  3273. // Z a2(1); // OK: direct initialization syntax used
  3274. // Z* p = new Z(1); // OK: direct initialization syntax used
  3275. // Z a4 = (Z)1; // OK: explicit cast used
  3276. // Z a5 = static_cast<Z>(1); // OK: explicit cast used
  3277. public void test12_3_1s2() throws Exception {
  3278. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3279. }
  3280. // class X {
  3281. // // ...
  3282. // public:
  3283. // operator int();
  3284. // };
  3285. // void f(X a)
  3286. // {
  3287. // int i = int(a);
  3288. // i = (int)a;
  3289. // i = a;
  3290. // }
  3291. public void test12_3_2s2() throws Exception {
  3292. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3293. }
  3294. // void g(X a, X b)
  3295. // {
  3296. // int i = (a) ? 1+a : 0;
  3297. // int j = (a&&b) ? a+b : i;
  3298. // if (a) { // ...
  3299. // }
  3300. // }
  3301. public void test12_3_2s3() throws Exception {
  3302. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3303. }
  3304. // struct B {
  3305. // virtual ~B() { }
  3306. // };
  3307. // struct D : B {
  3308. // ~D() { }
  3309. // };
  3310. // D D_object;
  3311. // typedef B B_alias;
  3312. // B* B_ptr = &D_object;
  3313. // void f() {
  3314. // D_object.B::~B(); //1 // calls B's destructor
  3315. // B_ptr->~B(); //2 // calls D's destructor
  3316. // B_ptr->~B_alias(); //3 // calls D's destructor
  3317. // B_ptr->B_alias::~B(); //4 // calls B's destructor
  3318. // B_ptr->B_alias::~B_alias(); //5 // error, no B_alias in class B
  3319. // }
  3320. public void test12_4s12() throws Exception {
  3321. final String code = getAboveComment();
  3322. parse(code, ParserLanguage.CPP, false, 0);
  3323. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  3324. ICPPFunction dtor= bh.assertNonProblem("~B() {", 2);
  3325. ICPPFunction d= bh.assertNonProblem("~B(); //1", 2);
  3326. assertSame(dtor, d);
  3327. d= bh.assertNonProblem("~B(); //2", 2);
  3328. assertSame(dtor, d);
  3329. d= bh.assertNonProblem("~B_alias(); //3", 8);
  3330. assertSame(dtor, d);
  3331. d= bh.assertNonProblem("~B(); //4", 2);
  3332. assertSame(dtor, d);
  3333. bh.assertProblem("~B_alias(); //5", 8);
  3334. }
  3335. // void* operator new(size_t, void* p) { return p; }
  3336. // struct X {
  3337. // // ...
  3338. // X(int);
  3339. // ~X();
  3340. // };
  3341. // void f(X* p);
  3342. // void g() // rare, specialized use:
  3343. // {
  3344. // char* buf = new char[sizeof(X)];
  3345. // X* p = new(buf) X(222); // use buf[] and initialize
  3346. // f(p);
  3347. // p->X::~X(); //cleanup
  3348. // }
  3349. public void test12_4s13() throws Exception {
  3350. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3351. }
  3352. // class Arena;
  3353. // struct B {
  3354. // void* operator new(size_t, Arena*);
  3355. // };
  3356. // struct D1 : B {
  3357. // };
  3358. // Arena* ap;
  3359. // void foo(int i)
  3360. // {
  3361. // new (ap) D1; // calls B::operator new(size_t, Arena*)
  3362. // new D1[i]; // calls ::operator new[](size_t)
  3363. // new D1; // illformed: ::operator new(size_t) hidden
  3364. // }
  3365. public void test12_5s2() throws Exception {
  3366. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3367. }
  3368. // class X {
  3369. // // ...
  3370. // void operator delete(void*);
  3371. // void operator delete[](void*, size_t);
  3372. // };
  3373. // class Y {
  3374. // // ...
  3375. // void operator delete(void*, size_t);
  3376. // void operator delete[](void*);
  3377. // };
  3378. public void test12_5s6() throws Exception {
  3379. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3380. }
  3381. // class complex {
  3382. // // ...
  3383. // public:
  3384. // complex();
  3385. // complex(double);
  3386. // complex(double,double);
  3387. // // ...
  3388. // };
  3389. // complex sqrt(complex,complex);
  3390. // int foo() {
  3391. // complex a(1); // initialize by a call of
  3392. // // complex(double)
  3393. // complex b = a; // initialize by a copy of a
  3394. // complex c = complex(1,2); // construct complex(1,2)
  3395. // // using complex(double,double)
  3396. // // copy it into c
  3397. // complex d = sqrt(b,c); // call sqrt(complex,complex)
  3398. // // and copy the result into d
  3399. // complex e; // initialize by a call of
  3400. // // complex()
  3401. // complex f = 3; // construct complex(3) using
  3402. // // complex(double)
  3403. // // copy it into f
  3404. // complex g = { 1, 2 }; // error; constructor is required
  3405. // }
  3406. public void test12_6_1s1() throws Exception {
  3407. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3408. }
  3409. // class complex {
  3410. // // ...
  3411. // public:
  3412. // complex();
  3413. // complex(double);
  3414. // complex(double,double);
  3415. // // ...
  3416. // };
  3417. // complex v[6] = { 1,complex(1,2),complex(),2 };
  3418. // class X {
  3419. // public:
  3420. // int i;
  3421. // float f;
  3422. // complex c;
  3423. // } x = { 99, 88.8, 77.7 };
  3424. public void test12_6_1s2() throws Exception {
  3425. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3426. }
  3427. // struct A { A(); };
  3428. // typedef A global_A;
  3429. // struct B { };
  3430. // struct C: public A, public B { C(); };
  3431. // C::C(): global_A() { } // meminitializer for base A
  3432. public void test12_6_2s2a() throws Exception {
  3433. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3434. }
  3435. // struct A { A(); };
  3436. // struct B: public virtual A { };
  3437. // struct C: public A, public B { C(); };
  3438. // C::C(): A() { } // illformed: which A?
  3439. public void test12_6_2s2b() throws Exception {
  3440. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3441. }
  3442. // struct B1 { B1(int); };
  3443. // struct B2 { B2(int); };
  3444. // struct D : B1, B2 {
  3445. // D(int);
  3446. // B1 b;
  3447. // const int c;
  3448. // };
  3449. // D::D(int a) : B2(a+1), B1(a+2), c(a+3), b(a+4)
  3450. // { }
  3451. // D d(10);
  3452. public void test12_6_2s3() throws Exception {
  3453. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3454. }
  3455. // class V {
  3456. // public:
  3457. // V();
  3458. // V(int);
  3459. // // ...
  3460. // };
  3461. // class A : public virtual V {
  3462. // public:
  3463. // A();
  3464. // A(int);
  3465. // // ...
  3466. // };
  3467. // class B : public virtual V {
  3468. // public:
  3469. // B();
  3470. // B(int);
  3471. // // ...
  3472. // };
  3473. // class C : public A, public B, private virtual V {
  3474. // public:
  3475. // C();
  3476. // C(int);
  3477. // // ...
  3478. // };
  3479. // A::A(int i) : V(i) { }
  3480. // B::B(int i) { }
  3481. // C::C(int i) { }
  3482. // V v(1); // use V(int)
  3483. // A a(2); // use V(int)
  3484. // B b(3); // use V()
  3485. // C c(4); // use V()
  3486. public void test12_6_2s6() throws Exception {
  3487. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3488. }
  3489. // class X {
  3490. // int a;
  3491. // int b;
  3492. // int i;
  3493. // int j;
  3494. // public:
  3495. // const int& r;
  3496. // X(int i): r(a), b(i), i(i), j(this->i) {}
  3497. // };
  3498. public void test12_6_2s7() throws Exception {
  3499. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3500. }
  3501. // class A {
  3502. // public:
  3503. // A(int);
  3504. // };
  3505. // class B : public A {
  3506. // int j;
  3507. // public:
  3508. // int f();
  3509. // B() : A(f()), // undefined: calls member function
  3510. // // but base A not yet initialized
  3511. // j(f()) { } // welldefined: bases are all initialized
  3512. // };
  3513. // class C {
  3514. // public:
  3515. // C(int);
  3516. // };
  3517. // class D : public B, C {
  3518. // int i;
  3519. // public:
  3520. // D() : C(f()), // undefined: calls member function
  3521. // // but base C not yet initialized
  3522. // i(f()) {} // welldefined: bases are all initialized
  3523. // };
  3524. public void test12_6_2s8() throws Exception {
  3525. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3526. }
  3527. // struct X { int i; };
  3528. // struct Y : X { };
  3529. // struct A { int a; };
  3530. // struct B : public A { int j; Y y; };
  3531. // extern B bobj;
  3532. // B* pb = &bobj; // OK
  3533. // int* p1 = &bobj.a; // undefined, refers to base class member
  3534. // int* p2 = &bobj.y.i; // undefined, refers to member's member
  3535. // A* pa = &bobj; // undefined, upcast to a base class type
  3536. // B bobj; // definition of bobj
  3537. // extern X xobj;
  3538. // int* p3 = &xobj.i; // OK, X is a POD class
  3539. // X xobj;
  3540. public void test12_7s1_a() throws Exception {
  3541. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3542. }
  3543. // struct W { int j; };
  3544. // struct X : public virtual W { };
  3545. // struct Y {
  3546. // int *p;
  3547. // X x;
  3548. // Y() : p(&x.j) // undefined, x is not yet constructed
  3549. // { }
  3550. // };
  3551. public void test12_7s1_b() throws Exception {
  3552. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3553. }
  3554. // class V {
  3555. // public:
  3556. // virtual void f();
  3557. // virtual void g();
  3558. // };
  3559. // class A : public virtual V {
  3560. // public:
  3561. // virtual void f();
  3562. // };
  3563. // class B : public virtual V {
  3564. // public:
  3565. // virtual void g();
  3566. // B(V*, A*);
  3567. // };
  3568. // class D : public A, B {
  3569. // public:
  3570. // virtual void f();
  3571. // virtual void g();
  3572. // D() : B((A*)this, this) { }
  3573. // };
  3574. // B::B(V* v, A* a) {
  3575. // f(); //calls V::f, not A::f
  3576. // g(); //calls B::g, not D::g
  3577. // v->g(); // v is base of B, the call is welldefined, calls B::g
  3578. // a->f(); //undefined behavior, a's type not a base of B
  3579. // }
  3580. public void test12_7s3() throws Exception {
  3581. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3582. }
  3583. // class V {
  3584. // public:
  3585. // virtual void f();
  3586. // };
  3587. // class A : public virtual V { };
  3588. // class B : public virtual V {
  3589. // public:
  3590. // B(V*, A*);
  3591. // };
  3592. // class D : public A, B {
  3593. // public:
  3594. // D() : B((A*)this, this) { }
  3595. // };
  3596. // B::B(V* v, A* a) {
  3597. // typeid(*this); // type_info for B
  3598. // typeid(*v); //welldefined: *v has type V, a base of B
  3599. // // yields type_info for B
  3600. // typeid(*a); //undefined behavior: type A not a base of B
  3601. // dynamic_cast<B*>(v); // welldefined: v of type V*, V base of B
  3602. // // results in B*
  3603. // dynamic_cast<B*>(a); // undefined behavior,
  3604. // // a has type A*, A not a base of B
  3605. // }
  3606. public void test12_7s6() throws Exception {
  3607. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3608. }
  3609. // class X {
  3610. // // ...
  3611. // public:
  3612. // X(int);
  3613. // X(const X&, int = 1);
  3614. // };
  3615. // X a(1); // calls X(int);
  3616. // X b(a, 0); // calls X(const X&, int);
  3617. // X c = b; // calls X(const X&, int);
  3618. public void test12_8s2a() throws Exception {
  3619. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3620. }
  3621. // class X {
  3622. // // ...
  3623. // public:
  3624. // X(const X&);
  3625. // X(X&); //OK
  3626. // };
  3627. public void test12_8s2b() throws Exception {
  3628. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3629. }
  3630. // struct X {
  3631. // X(); //default constructor
  3632. // X(X&); //copy constructor with a nonconst parameter
  3633. // };
  3634. // const X cx;
  3635. // X x = cx; // error - X::X(X&) cannot copy cx into x
  3636. public void test12_8s2c() throws Exception {
  3637. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3638. }
  3639. // struct S {
  3640. // template<typename T> S(T);
  3641. // };
  3642. // S f();
  3643. // void g() {
  3644. // S a( f() ); // does not instantiate member template
  3645. // }
  3646. public void test12_8s3() throws Exception {
  3647. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3648. }
  3649. // void h(int());
  3650. // void h(int (*)()); // redeclaration of h(int())
  3651. // void h(int x()) { } // definition of h(int())
  3652. // void h(int (*x)()) { } // illformed: redefinition of h(int())
  3653. public void test12_8s3d() throws Exception {
  3654. parse(getAboveComment(), ParserLanguage.CPP, true, 1);
  3655. }
  3656. // struct X {
  3657. // X(const X&, int);
  3658. // };
  3659. public void test12_8s4a() throws Exception {
  3660. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3661. }
  3662. // struct X {
  3663. // X(const X&, int);
  3664. // };
  3665. // X::X(const X& x, int i =0) { }
  3666. public void test12_8s4b() throws Exception {
  3667. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3668. }
  3669. // struct X {
  3670. // X();
  3671. // X& operator=(X&);
  3672. // };
  3673. // const X cx;
  3674. // X x;
  3675. // void f() {
  3676. // x = cx; // error:
  3677. // // X::operator=(X&) cannot assign cx into x
  3678. // }
  3679. public void test12_8s9() throws Exception {
  3680. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3681. }
  3682. // struct V { };
  3683. // struct A : virtual V { };
  3684. // struct B : virtual V { };
  3685. // struct C : B, A { };
  3686. public void test12_8s13() throws Exception {
  3687. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3688. }
  3689. // class Thing {
  3690. // public:
  3691. // Thing();
  3692. // ~Thing();
  3693. // Thing(const Thing&);
  3694. // Thing operator=(const Thing&);
  3695. // void fun();
  3696. // };
  3697. // Thing f() {
  3698. // Thing t;
  3699. // return t;
  3700. // }
  3701. // Thing t2 = f();
  3702. public void test12_8s15() throws Exception {
  3703. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3704. }
  3705. // double abs(double);
  3706. // int abs(int);
  3707. // int foo() {
  3708. // abs(1); //call abs(int);
  3709. // abs(1.0); //call abs(double);
  3710. // }
  3711. public void test13s2() throws Exception {
  3712. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3713. }
  3714. // class X {
  3715. // static void f();
  3716. // void f(); // illformed
  3717. // void f() const; // illformed
  3718. // void f() const volatile; // illformed
  3719. // void g();
  3720. // void g() const; // OK: no static g
  3721. // void g() const volatile; // OK: no static g
  3722. // };
  3723. public void test12_1s2() throws Exception {
  3724. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3725. }
  3726. // typedef int Int;
  3727. // void f(int i);
  3728. // void f(Int i); // OK: redeclaration of f(int)
  3729. // void f(int i) { }
  3730. // void f(Int i) { } // error: redefinition of f(int)
  3731. public void test12_1s3a() throws Exception {
  3732. parse(getAboveComment(), ParserLanguage.CPP, true, 1);
  3733. }
  3734. // enum E { a };
  3735. // void f(int i) { }
  3736. // void f(E i) { }
  3737. public void test12_1s3b() throws Exception {
  3738. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3739. }
  3740. // int f(char*);
  3741. // int f(char[]); // same as f(char*);
  3742. // int f(char[7]); // same as f(char*);
  3743. // int f(char[9]); // same as f(char*);
  3744. // int g(char(*)[10]);
  3745. // int g(char[5][10]); // same as g(char(*)[10]);
  3746. // int g(char[7][10]); // same as g(char(*)[10]);
  3747. // int g(char(*)[20]); // different from g(char(*)[10]);
  3748. public void test12_1s3c() throws Exception {
  3749. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3750. }
  3751. // typedef const int cInt;
  3752. // int f (int);
  3753. // int f (const int); // redeclaration of f(int)
  3754. // int f (int) { } // definition of f(int)
  3755. // int f (cInt) { } // error: redefinition of f(int)
  3756. public void test12_8s3e() throws Exception {
  3757. String[] problems= {"f"};
  3758. parse(getAboveComment(), ParserLanguage.CPP, problems);
  3759. }
  3760. // void f (int i, int j);
  3761. // void f (int i, int j = 99); // OK: redeclaration of f(int, int)
  3762. // void f (int i = 88, int j); // OK: redeclaration of f(int, int)
  3763. // void f (); // OK: overloaded declaration of f
  3764. // void prog ()
  3765. // {
  3766. // f (1, 2); // OK: call f(int, int)
  3767. // f (1); // OK: call f(int, int)
  3768. // f (); // Error: f(int, int) or f()?
  3769. // }
  3770. public void test12_8s3f() throws Exception {
  3771. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3772. }
  3773. // class B {
  3774. // public:
  3775. // int f(int);
  3776. // };
  3777. // class D : public B {
  3778. // public:
  3779. // int f(char*);
  3780. // };
  3781. public void test13_2s1a() throws Exception {
  3782. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3783. }
  3784. // class B {
  3785. // public:
  3786. // int f(int);
  3787. // };
  3788. // class D : public B {
  3789. // public:
  3790. // int f(char*);
  3791. // };
  3792. // void h(D* pd)
  3793. // {
  3794. // pd->f(1); //error:
  3795. // // D::f(char*) hides B::f(int)
  3796. // pd->B::f(1); //OK
  3797. // pd->f("Ben"); //OK, calls D::f
  3798. // }
  3799. public void test13_2s1b() throws Exception {
  3800. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3801. }
  3802. // int f(char*);
  3803. // void g()
  3804. // {
  3805. // extern int f(int);
  3806. // f("asdf"); //error: f(int) hides f(char*)
  3807. // // so there is no f(char*) in this scope
  3808. // }
  3809. // void caller ()
  3810. // {
  3811. // extern void callee(int, int);
  3812. // {
  3813. // extern void callee(int); // hides callee(int, int)
  3814. // callee(88, 99); // error: only callee(int) in scope
  3815. // }
  3816. // }
  3817. public void test13_2s2() throws Exception {
  3818. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3819. }
  3820. // class buffer {
  3821. // private:
  3822. // char* p;
  3823. // int size;
  3824. // protected:
  3825. // buffer(int s, char* store) { size = s; p = store; }
  3826. // // ...
  3827. // public:
  3828. // buffer(int s) { p = new char[size = s]; }
  3829. // // ...
  3830. // };
  3831. public void test13_2s3() throws Exception {
  3832. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3833. }
  3834. // class T {
  3835. // public:
  3836. // T();
  3837. // // ...
  3838. // };
  3839. // class C : T {
  3840. // public:
  3841. // C(int);
  3842. // // ...
  3843. // };
  3844. // T a = 1; // illformed: T(C(1)) not tried
  3845. public void test13_3_1s6() throws Exception {
  3846. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3847. }
  3848. // int f1(int);
  3849. // int f2(float);
  3850. // typedef int (*fp1)(int);
  3851. // typedef int (*fp2)(float);
  3852. // struct A {
  3853. // operator fp1() { return f1; }
  3854. // operator fp2() { return f2; }
  3855. // } a;
  3856. // int i = a(1); // Calls f1 via pointer returned from
  3857. // // conversion function
  3858. public void test13_3_1_1_2s4() throws Exception {
  3859. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3860. }
  3861. // class String {
  3862. // public:
  3863. // String (const String&);
  3864. // String (char*);
  3865. // operator char* ();
  3866. // };
  3867. // String operator + (const String&, const String&);
  3868. // void f(void)
  3869. // {
  3870. // char* p= "one" + "two"; // illformed because neither
  3871. // // operand has user defined type
  3872. // int I = 1 + 1; // Always evaluates to 2 even if
  3873. // // user defined types exist which
  3874. // // would perform the operation.
  3875. // }
  3876. public void test13_3_1_2s1() throws Exception {
  3877. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3878. }
  3879. // struct A {
  3880. // operator int();
  3881. // };
  3882. // A operator+(const A&, const A&);
  3883. // void m() {
  3884. // A a, b;
  3885. // a + b; // operator+(a,b) chosen over int(a) + int(b)
  3886. // }
  3887. public void test13_3_1_2s6() throws Exception {
  3888. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3889. }
  3890. // struct A {
  3891. // A();
  3892. // operator int();
  3893. // operator double();
  3894. // } a;
  3895. // int i = a; // a.operator int() followed by no conversion
  3896. // // is better than a.operator double() followed by
  3897. // // a conversion to int
  3898. // float x = a; // ambiguous: both possibilities require conversions,
  3899. // // and neither is better than the other
  3900. public void test13_3_3s1() throws Exception {
  3901. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3902. }
  3903. // void Fcn(const int*, short);
  3904. // void Fcn(int*, int);
  3905. // int i;
  3906. // short s = 0;
  3907. // void f() {
  3908. // Fcn(&i, s); // is ambiguous because
  3909. // // &i -> int* is better than &i -> const int*
  3910. // // but s -> short is also better than s -> int
  3911. // Fcn(&i, 1L); // calls Fcn(int*, int), because
  3912. // // &i -> int* is better than &i -> const int*
  3913. // // and 1L -> short and 1L -> int are indistinguishable
  3914. // Fcn(&i,'c'); //callsFcn(int*, int), because
  3915. // // &i -> int* is better than &i -> const int*
  3916. // // and c -> int is better than c -> short
  3917. // }
  3918. public void test13_3_3s3() throws Exception {
  3919. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3920. }
  3921. // class B;
  3922. // class A { A (B&); };
  3923. // class B { operator A (); };
  3924. // class C { C (B&); };
  3925. // void f(A) { }
  3926. // void f(C) { }
  3927. // B b;
  3928. // f(b); //ambiguous because b -> C via constructor and
  3929. // // b -> A via constructor or conversion function.
  3930. public void test13_3_3_1_1s2() throws Exception {
  3931. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  3932. }
  3933. // struct A {};
  3934. // struct B : public A {} b;
  3935. // int f(A&);
  3936. // int f(B&);
  3937. // int i = f(b); // Calls f(B&), an exact match, rather than
  3938. // // f(A&), a conversion
  3939. public void test13_3_3_1_4s1() throws Exception {
  3940. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3941. }
  3942. // int f(const int *);
  3943. // int f(int *);
  3944. // int i;
  3945. // int j = f(&i); // Calls f(int *)
  3946. public void test13_3_3_2s3a() throws Exception {
  3947. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3948. }
  3949. // int f(const int &);
  3950. // int f(int &);
  3951. // int g(const int &);
  3952. // int g(int);
  3953. // int i;
  3954. // int j = f(i); // Calls f(int &)
  3955. // int k = g(i); // ambiguous
  3956. // class X {
  3957. // public:
  3958. // void f() const;
  3959. // void f();
  3960. // };
  3961. // void g(const X& a, X b)
  3962. // {
  3963. // a.f(); //CallsX::f() const
  3964. // b.f(); //Calls X::f()
  3965. // }
  3966. public void test13_3_3_2s3b() throws Exception {
  3967. String[] problems= {"g"};
  3968. parse(getAboveComment(), ParserLanguage.CPP, problems);
  3969. }
  3970. // struct A {
  3971. // operator short();
  3972. // } a;
  3973. // int f(int);
  3974. // int f(float);
  3975. // int i = f(a); // Calls f(int), because short -> int is
  3976. // // better than short -> float.
  3977. public void test13_3_3_2s3c() throws Exception {
  3978. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3979. }
  3980. // struct A {};
  3981. // struct B : public A {};
  3982. // struct C : public B {};
  3983. // C *pc;
  3984. // int f(A *);
  3985. // int f(B *);
  3986. // int i = f(pc); // Calls f(B *)
  3987. public void test13_3_3_2s4() throws Exception {
  3988. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  3989. }
  3990. // struct X {
  3991. // int f(int);
  3992. // static int f(long);
  3993. // };
  3994. // int (X::*p1)(int) = &X::f; // OK
  3995. // int (*p2)(int) = &X::f; // error: mismatch
  3996. // int (*p3)(long) = &X::f; // OK
  3997. // int (X::*p4)(long) = &X::f; // error: mismatch
  3998. // int (*p6)(long) = &(X::f); // OK
  3999. public void test13_4s5b() throws Exception {
  4000. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4001. }
  4002. // class complex {
  4003. // public:
  4004. // complex operator+(complex a) {}
  4005. // };
  4006. // int n;
  4007. // int foo(complex &a, complex &b) {
  4008. // complex z = a.operator+(b); // complex z = a+b;
  4009. // void* p = operator new(sizeof(int)*n);
  4010. // }
  4011. public void test13_5s4() throws Exception {
  4012. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4013. }
  4014. // struct B {
  4015. // virtual int operator= (int);
  4016. // virtual B& operator= (const B&);
  4017. // };
  4018. // struct D : B {
  4019. // virtual int operator= (int);
  4020. // virtual D& operator= (const B&);
  4021. // };
  4022. // D dobj1;
  4023. // D dobj2;
  4024. // B* bptr = &dobj1;
  4025. // void f() {
  4026. // bptr->operator=(99); // calls D::operator=(int)
  4027. // *bptr = 99; // ditto
  4028. // bptr->operator=(dobj2); // calls D::operator=(const B&)
  4029. // *bptr = dobj2; // ditto
  4030. // dobj1 = dobj2; // calls implicitlydeclared
  4031. // // D::operator=(const D&)
  4032. // }
  4033. public void test13_5_3s2() throws Exception {
  4034. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4035. }
  4036. // class X {
  4037. // public:
  4038. // X& operator++(); // prefix ++a
  4039. // X operator++(int); // postfix a++
  4040. // };
  4041. // class Y { };
  4042. // Y& operator++(Y&); // prefix ++b
  4043. // Y operator++(Y&, int); // postfix b++
  4044. // void f(X a, Y b) {
  4045. // ++a; // a.operator++();
  4046. // a++; // a.operator++(0);
  4047. // ++b; // operator++(b);
  4048. // b++; // operator++(b, 0);
  4049. // a.operator++(); // explicit call: like ++a;
  4050. // a.operator++(0); // explicit call: like a++;
  4051. // operator++(b); //explicit call: like ++b;
  4052. // operator++(b, 0); // explicit call: like b++;
  4053. // }
  4054. public void test13_5_7s1() throws Exception {
  4055. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4056. }
  4057. // template<const X& x, int i> void f()
  4058. // {
  4059. // i++; //error: change of template parameter
  4060. // value
  4061. // &x; //OK
  4062. // &i; //error: address of nonreference template parameter
  4063. // int& ri = i; // error: nonconst reference bound to temporary
  4064. // const int& cri = i; // OK: const reference bound to temporary
  4065. // }
  4066. public void test14_1s6() throws Exception {
  4067. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4068. }
  4069. // template<double d> class X; // error
  4070. // template<double* pd> class Y; // OK
  4071. // template<double& rd> class Z; // OK
  4072. public void test14_1s7() throws Exception {
  4073. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4074. }
  4075. // template<int *a> struct R { };
  4076. // template<int b[5]> struct S { };
  4077. // int *p;
  4078. // R<p> w; // OK
  4079. // S<p> x; // OK due to parameter adjustment
  4080. // int v[5];
  4081. // R<v> y; // OK due to implicit argument conversion
  4082. // S<v> z; // OK due to both adjustment and conversion
  4083. public void test14_1s8() throws Exception { // TODO raised bug 90668
  4084. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4085. }
  4086. // template<class T1, class T2 = int> class A;
  4087. // template<class T1 = int, class T2> class A;
  4088. public void test14_1s10a() throws Exception {
  4089. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4090. }
  4091. // template<class T1 = int, class T2 = int> class A;
  4092. public void test14_1s10b() throws Exception {
  4093. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4094. }
  4095. // template<class T1 = int, class T2> class B; // error
  4096. public void test14_1s11() throws Exception {
  4097. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4098. }
  4099. // template<class T = int> class X;
  4100. // template<class T = int> class X { }; // error
  4101. public void test14_1s12() throws Exception {
  4102. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4103. }
  4104. // template<class T, T* p, class U = T> class X { };
  4105. // template<class T> void f(T* p = new T);
  4106. public void test14_1s13() throws Exception {
  4107. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4108. }
  4109. // template<int i = (3 > 4) > // OK
  4110. // class Y { };
  4111. public void test14_1s15() throws Exception {
  4112. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4113. }
  4114. // template<int i> class X { };
  4115. // X<(1>2)> x2; // OK
  4116. // template<class T> class Y { };
  4117. // Y< X<1> > x3; // OK
  4118. // // with C++0x this is no longer valid:
  4119. // // Y<X<6>> 1> > x4; // OK: Y< X< (6>>1) > >
  4120. public void test14_2s3() throws Exception {
  4121. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4122. }
  4123. // class X {
  4124. // public:
  4125. // template<size_t> X* alloc();
  4126. // template<size_t> static X* adjust();
  4127. // };
  4128. // template<class T> void f(T* p)
  4129. // {
  4130. // T* p1 = p>
  4131. // alloc<200>(); // illformed: < means less than
  4132. // T* p2 = p->template alloc<200>();
  4133. // // OK: < starts template argument list
  4134. // T::adjust<100>();
  4135. // // illformed: < means less than
  4136. // T::template adjust<100>();
  4137. // // OK: < starts explicit qualification
  4138. // }
  4139. public void test14_2s4() throws Exception {
  4140. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4141. }
  4142. // template<typename T> class complex {
  4143. // complex(T,T) {}
  4144. // };
  4145. // template<class T> class Array {
  4146. // T* v;
  4147. // int sz;
  4148. // public:
  4149. // explicit Array(int);
  4150. // T& operator[](int);
  4151. // T& elem(int i) { return v[i]; }
  4152. // // ...
  4153. // };
  4154. // Array<int> v1(20);
  4155. // typedef complex<double> dcomplex;
  4156. // Array<dcomplex> v2(30);
  4157. // Array<dcomplex> v3(40);
  4158. // void bar() {
  4159. // v1[3] = 7;
  4160. // v2[3] = v3.elem(4) = dcomplex(7,8);
  4161. // }
  4162. public void test14_3s1() throws Exception {
  4163. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4164. }
  4165. // template<class T> class X {
  4166. // static T t;
  4167. // };
  4168. // class Y {
  4169. // private:
  4170. // struct S { };
  4171. // X<S> x; // OK: S is accessible
  4172. // // X<Y::S> has a static member of type Y::S
  4173. // // OK: even though Y::S is private
  4174. // };
  4175. // X<Y::S> y; // error: S not accessible
  4176. public void test14_3s3() throws Exception {
  4177. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4178. }
  4179. // template<class T> struct A {
  4180. // ~A();
  4181. // };
  4182. // void f(A<int>* p, A<int>* q) {
  4183. // p->A<int>::~A(); // OK: destructor call
  4184. // q->A<int>::~A<int>(); // OK: destructor call
  4185. // }
  4186. public void test14_3s5() throws Exception {
  4187. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4188. }
  4189. // template <class T> class X { };
  4190. // void f()
  4191. // {
  4192. // struct S { };
  4193. // X<S> x3; // error: local type used as templateargument
  4194. // X<S*> x4; // error: pointer to local type used as templateargument
  4195. // }
  4196. public void test14_3_1s2() throws Exception {
  4197. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4198. }
  4199. // template<class T> struct A {
  4200. // static T t;
  4201. // };
  4202. // typedef int function();
  4203. // A<function> a; // illformed: would declare A<function>::t
  4204. // // as a static member function
  4205. public void test14_3_1s3() throws Exception {
  4206. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4207. }
  4208. // template<class T> class A { // primary template
  4209. // int x;
  4210. // };
  4211. // template<class T> class A<T*> { // partial specialization
  4212. // long x;
  4213. // };
  4214. // template<template<class U> class V> class C {
  4215. // V<int> y;
  4216. // V<int*> z;
  4217. // };
  4218. // C<A> c; // V<int> within C<A> uses the primary template,
  4219. // // so c.y.x has type int
  4220. // // V<int*> within C<A> uses the partial specialization,
  4221. // // so c.z.x has type long
  4222. public void test14_3_3s2() throws Exception {
  4223. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4224. }
  4225. // template<class E, int size> class buffer { };
  4226. // buffer<char,2*512> x;
  4227. // buffer<char,1024> y;
  4228. public void test14_2s1a() throws Exception {
  4229. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4230. }
  4231. // template<class T, void(*err_fct)()> class list { };
  4232. // list<int,&error_handler1> x1;
  4233. // list<int,&error_handler2> x2;
  4234. // list<int,&error_handler2> x3;
  4235. // list<char,&error_handler2> x4;
  4236. public void test14_4s1b() throws Exception {
  4237. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4238. }
  4239. // template<class T> class Array {
  4240. // T* v;
  4241. // int sz;
  4242. // public:
  4243. // explicit Array(int);
  4244. // T& operator[](int);
  4245. // T& elem(int i) { return v[i]; }
  4246. // // ...
  4247. // };
  4248. public void test14_5_1s2() throws Exception {
  4249. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4250. }
  4251. // template<class T1, class T2> struct A {
  4252. // void f1();
  4253. // void f2();
  4254. // };
  4255. // template<class T2, class T1> void A<T2,T1>::f1() { } // OK
  4256. public void test14_5_1s3a() throws Exception {
  4257. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4258. }
  4259. // void error(const char*);
  4260. // template<class T> class Array {
  4261. // T* v;
  4262. // int sz;
  4263. // public:
  4264. // explicit Array(int);
  4265. // T& operator[](int);
  4266. // T& elem(int i) { return v[i]; }
  4267. // // ...
  4268. // };
  4269. // template<class T> T& Array<T>::operator[](int i)
  4270. // {
  4271. // if (i<0 || sz<=i) error("Array: range error");
  4272. // return v[i];
  4273. // }
  4274. public void test14_5_1_1s1() throws Exception {
  4275. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4276. }
  4277. // void test() {
  4278. // Array<int> v1(20);
  4279. // Array<dcomplex> v2(30);
  4280. // v1[3] = 7; // Array<int>::operator[]()
  4281. // v2[3] = dcomplex(7,8); // Array<dcomplex>::operator[]()
  4282. // }
  4283. public void test14_5_1_1s2() throws Exception {
  4284. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4285. }
  4286. // template<class T> struct A {
  4287. // class B;
  4288. // };
  4289. // A<int>::B* b1; // OK: requires A to be defined but not A::B
  4290. // template<class T> class A<T>::B { };
  4291. // A<int>::B b2; // OK: requires A::B to be defined
  4292. public void test14_5_1_2s1() throws Exception {
  4293. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4294. }
  4295. // template<class T> class string {
  4296. // public:
  4297. // template<class T2> int compare(const T2&);
  4298. // template<class T2> string(const string<T2>& s) { }
  4299. // // ...
  4300. // };
  4301. // template<class T> template<class T2> int string<T>::compare(const T2& s)
  4302. // {
  4303. // // ...
  4304. // }
  4305. public void test14_5_2s1() throws Exception {
  4306. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4307. }
  4308. // class B {
  4309. // virtual void f(int);
  4310. // };
  4311. // class D : public B {
  4312. // template <class T> void f(T); // does not override B::f(int)
  4313. // void f(int i) { f<>(i); } // overriding function that calls
  4314. // // the template instantiation
  4315. // };
  4316. public void test14_5_2s4() throws Exception {
  4317. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4318. }
  4319. // struct A {
  4320. // template <class T> operator T*();
  4321. // };
  4322. // template <class T> A::operator T*(){ return 0; }
  4323. // template <> A::operator char*(){ return 0; } // specialization
  4324. // template A::operator void*(); // explicit instantiation
  4325. // int main()
  4326. // {
  4327. // A a;
  4328. // int* ip;
  4329. // ip = a.operator int*(); // explicit call to template operator
  4330. // // A::operator int*()
  4331. // }
  4332. public void test14_5_2s5() throws Exception {
  4333. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4334. }
  4335. // template<class T> class X {
  4336. // static T s;
  4337. // };
  4338. // template<class T> T X<T>::s = 0;
  4339. public void test14_5_1_3s1() throws Exception {
  4340. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4341. }
  4342. // template<class T> class task;
  4343. // template<class T> task<T>* preempt(task<T>*);
  4344. // template<class T> class task {
  4345. // // ...
  4346. // friend void next_time();
  4347. // friend void process(task<T>*);
  4348. // friend task<T>* preempt<T>(task<T>*);
  4349. // template<class C> friend int func(C);
  4350. // friend class task<int>;
  4351. // template<class P> friend class frd;
  4352. // // ...
  4353. // };
  4354. public void test14_5_4s1() throws Exception {
  4355. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4356. }
  4357. // namespace N {
  4358. // template <class T> void f(T);
  4359. // void g(int);
  4360. // namespace M {
  4361. // template <class T> void h(T);
  4362. // template <class T> void i(T);
  4363. // struct A {
  4364. // friend void f<>(int); // illformed- N::f
  4365. // friend void h<>(int); // OK - M::h
  4366. // friend void g(int); // OK - new decl of M::g
  4367. // template <class T> void i(T);
  4368. // friend void i<>(int); // illformed- A::i
  4369. // };
  4370. // }
  4371. // }
  4372. public void test14_5_4s2() throws Exception {
  4373. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4374. }
  4375. // class A {
  4376. // template<class T> friend class B; // OK
  4377. // template<class T> friend void f(T){ } // OK
  4378. // };
  4379. public void test14_5_4s3() throws Exception {
  4380. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4381. }
  4382. // class X {
  4383. // template<class T> friend struct A;
  4384. // class Y { };
  4385. // };
  4386. // template<class T> struct A { X::Y ab; }; // OK
  4387. // template<class T> struct A<T*> { X::Y ab; }; // OK
  4388. public void test14_5_4s4() throws Exception {
  4389. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4390. }
  4391. // template<class T> struct A {
  4392. // struct B { };
  4393. // void f();
  4394. // };
  4395. // class C {
  4396. // template<class T> friend struct A<T>::B;
  4397. // template<class T> friend void A<T>::f();
  4398. // };
  4399. public void test14_5_4s6() throws Exception {
  4400. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4401. }
  4402. // template<class T> struct A {
  4403. // template<class T2> struct B {}; // #1
  4404. // template<class T2> struct B<T2*> {}; // #2
  4405. // };
  4406. // template<> template<class T2> struct A<short>::B {}; // #3
  4407. // A<char>::B<int*> abcip; // uses #2
  4408. // A<short>::B<int*> absip; // uses #3
  4409. // A<char>::B<int> abci; // uses #1
  4410. public void test14_5_5_3s2() throws Exception {
  4411. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4412. }
  4413. // template<class T1, class T2, int I> class A { }; // #1
  4414. // template<class T, int I> class A<T, T*, I> { }; // #2
  4415. // template<class T1, class T2, int I> class A<T1*, T2, I> { }; // #3
  4416. // template<class T> class A<int, T*, 5> { }; // #4
  4417. // template<class T1, class T2, int I> class A<T1, T2*, I> { }; // #5
  4418. public void test14_5_5s4() throws Exception {
  4419. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4420. }
  4421. // template <int I, int J> struct B {};
  4422. // template <int I> struct B<I, I> {}; // OK
  4423. public void test14_5_5s9b() throws Exception {
  4424. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4425. }
  4426. // template<class T1, class T2, int I> class A { }; // #1
  4427. // template<class T, int I> class A<T, T*, I> { }; // #2
  4428. // template<class T1, class T2, int I> class A<T1*, T2, I> { }; // #3
  4429. // template<class T> class A<int, T*, 5> { }; // #4
  4430. // template<class T1, class T2, int I> class A<T1, T2*, I> { }; // #5
  4431. // A<int, int, 1> a1; // uses #1
  4432. // A<int, int*, 1> a2; // uses #2, T is int, I is 1
  4433. // A<int, char*, 5> a3; // uses #4, T is char
  4434. // A<int, char*, 1> a4; // uses #5, T1 is int, T2 is char, I is 1
  4435. public void test14_5_5_1s2a() throws Exception {
  4436. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4437. }
  4438. // template<class T1, class T2, int I> class A { }; // #1
  4439. // template<class T, int I> class A<T, T*, I> { }; // #2
  4440. // template<class T1, class T2, int I> class A<T1*, T2, I> { }; // #3
  4441. // template<class T> class A<int, T*, 5> { }; // #4
  4442. // template<class T1, class T2, int I> class A<T1, T2*, I> { }; // #5
  4443. // A<int*, int*, 2> a5; // ambiguous: matches #3 and #5 : expect problem
  4444. public void test14_5_5_1s2b() throws Exception {
  4445. parse(getAboveComment(), ParserLanguage.CPP, true, 1);
  4446. }
  4447. // template<int I, int J, class T> class X { };
  4448. // template<int I, int J> class X<I, J, int> { }; // #1
  4449. // template<int I> class X<I, I, int> { }; // #2
  4450. // template<int I, int J> void f(X<I, J, int>); // #A
  4451. // template<int I> void f(X<I, I, int>); // #B
  4452. public void test14_5_5_2s2() throws Exception {
  4453. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4454. }
  4455. // // primary template
  4456. // template<class T, int I> struct A {
  4457. // void f();
  4458. // };
  4459. // template<class T, int I> void A<T,I>::f() { }
  4460. // // class template partial specialization
  4461. // template<class T> struct A<T,2> {
  4462. // void f();
  4463. // void g();
  4464. // void h();
  4465. // };
  4466. // // member of class template partial specialization
  4467. // template<class T> void A<T,2>::g() { }
  4468. // // explicit specialization
  4469. // template<> void A<char,2>::h() { }
  4470. // int main()
  4471. // {
  4472. // A<char,0> a0;
  4473. // A<char,2> a2;
  4474. // a0.f(); //OK, uses definition of primary template's member
  4475. // a2.g(); //OK, uses definition of
  4476. // // partial specialization's member
  4477. // a2.h(); //OK, uses definition of
  4478. // // explicit specialization's member
  4479. // a2.f(); //illformed, no definition of f for A<T,2>
  4480. // // the primary template is not used here
  4481. // }
  4482. public void test14_5_5_3s1() throws Exception {
  4483. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4484. }
  4485. // template<class T> class Array { };
  4486. // template<class T> void sort(Array<T>&);
  4487. public void test14_5_6s1() throws Exception {
  4488. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4489. }
  4490. // // file1.c
  4491. // template<class T>
  4492. // void f(T*);
  4493. // void g(int* p) {
  4494. // f(p); // call
  4495. // // f<int>(int*)
  4496. // }
  4497. public void test14_5_6_1s1a() throws Exception {
  4498. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4499. }
  4500. // // file2.c
  4501. // template<class T>
  4502. // void f(T);
  4503. // void h(int* p) {
  4504. // f(p); // call
  4505. // // f<int*>(int*)
  4506. // }
  4507. public void test14_5_6_1s1b() throws Exception {
  4508. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4509. }
  4510. // // Guaranteed to be the same
  4511. // template <int T> class A;
  4512. // template <int I> void f/*1*/(A<I>, A<I+10>);
  4513. // template <int I> void f/*2*/(A<I>, A<I+10>);
  4514. // // Guaranteed to be different
  4515. // template <int I> void f/*3*/(A<I>, A<I+11>);
  4516. public void test14_5_6_1s8a() throws Exception {
  4517. final String content= getAboveComment();
  4518. IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
  4519. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  4520. ICPPFunctionTemplate f1= bh.assertNonProblem("f/*1*/", 1);
  4521. ICPPFunctionTemplate f2= bh.assertNonProblem("f/*2*/", 1);
  4522. ICPPFunctionTemplate f3= bh.assertNonProblem("f/*3*/", 1);
  4523. assertSame(f1, f2);
  4524. assertNotSame(f1, f3);
  4525. }
  4526. // // Illformed, no diagnostic required
  4527. // template <int I> void f(A<I>, A<I+10>);
  4528. // template <int I> void f(A<I>, A<I+1+2+3+4>);
  4529. public void test14_5_6_1s8b() throws Exception {
  4530. //test is only for syntax, semantics are not checked here.
  4531. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4532. }
  4533. // struct A { };
  4534. // template<class T> struct B {
  4535. // template<class R> int operator*(R&); // #1
  4536. // };
  4537. // template<class T, class R> int operator*(T&, R&); // #2
  4538. // // The declaration of B::operator* is transformed into the equivalent of
  4539. // // template<class R> int operator*(B<A>&, R&); // #1a
  4540. // int main() {
  4541. // A a;
  4542. // B<A> b;
  4543. // b * a; // calls #1a
  4544. // }
  4545. public void test14_5_6_2s3() throws Exception {
  4546. String code= getAboveComment();
  4547. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  4548. IBinding op1= bh.assertNonProblem("operator*(R&)", -4);
  4549. IASTImplicitName name= bh.assertImplicitName("* a", 1, ICPPFunction.class);
  4550. ICPPTemplateInstance inst= (ICPPTemplateInstance) name.resolveBinding();
  4551. ICPPSpecialization templateSpecialization = (ICPPSpecialization) inst.getTemplateDefinition();
  4552. assertSame(op1, templateSpecialization.getSpecializedBinding());
  4553. }
  4554. // template<class T> struct A { A(); };
  4555. // template<class T> void f(T);
  4556. // template<class T> void f(T*);
  4557. // template<class T> void f(const T*);
  4558. // template<class T> void g(T);
  4559. // template<class T> void g(T&);
  4560. // template<class T> void h(const T&);
  4561. // template<class T> void h(A<T>&);
  4562. // void m() {
  4563. // const int *p;
  4564. // f(p); // f(const T*) is more specialized than f(T) or f(T*)
  4565. // float x;
  4566. // g(x); //Ambiguous: g(T) or g(T&)
  4567. // A<int> z;
  4568. // h(z); //overload resolution selects h(A<T>&)
  4569. // const A<int> z2;
  4570. // h(z2); // h(const T&) is called because h(A<T>&) is not callable
  4571. // }
  4572. public void test14_5_6_2s5() throws Exception {
  4573. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4574. }
  4575. // template<class T> void f(T); // #1
  4576. // template<class T> void f(T*, int=1); // #2
  4577. // template<class T> void g(T); // #3
  4578. // template<class T> void g(T*, ...); // #4
  4579. // int main() {
  4580. // int* ip;
  4581. // f(ip); //calls #2
  4582. // g(ip); //calls #4
  4583. // }
  4584. public void test14_5_6_2s6() throws Exception {
  4585. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4586. }
  4587. // // no B declared here
  4588. // class X;
  4589. // template<class T> class Y {
  4590. // class Z; // forward declaration of member class
  4591. // void f() {
  4592. // X* a1; // declare pointer to X
  4593. // T* a2; // declare pointer to T
  4594. // Y* a3; // declare pointer to Y<T>
  4595. // Z* a4; // declare pointer to Z
  4596. // typedef typename T::A TA;
  4597. // TA* a5; // declare pointer to T's A
  4598. // typename T::A* a6; // declare pointer to T's A
  4599. // T::A* a7; // T::A is not a type name:
  4600. // // multiply T::A by a7; illformed,
  4601. // // no visible declaration of a7
  4602. // B* a8; // B is not a type name:
  4603. // // multiply B by a8; illformed,
  4604. // // no visible declarations of B and a8
  4605. // }
  4606. // };
  4607. public void test14_6s2() throws Exception {
  4608. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4609. }
  4610. // struct A {
  4611. // struct X { };
  4612. // int X;
  4613. // };
  4614. // template<class T> void f(T t) {
  4615. // typename T::X x; // illformed: finds the data member X
  4616. // // not the member type X
  4617. // }
  4618. public void test14_6s4() throws Exception {
  4619. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4620. }
  4621. // template<class T> struct A {
  4622. // typedef int B;
  4623. // A::B b; // illformed: typename required before A::B
  4624. // void f(A<T>::B); // illformed: typename required before A<T>::B
  4625. // typename A::B g(); // OK
  4626. // };
  4627. public void test14_6s6() throws Exception {
  4628. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4629. }
  4630. // int j;
  4631. // template<class T> class X {
  4632. // // ...
  4633. // void f(T t, int i, char* p)
  4634. // {
  4635. // t = i; // diagnosed if X::f is instantiated
  4636. // // and the assignment to t is an error
  4637. // p = i; // may be diagnosed even if X::f is
  4638. // // not instantiated
  4639. // p = j; // may be diagnosed even if X::f is
  4640. // // not instantiated
  4641. // }
  4642. // void g(T t) {
  4643. // // +; //may be diagnosed even if X::g is
  4644. // // not instantiated
  4645. // }
  4646. // };
  4647. public void test14_6s7() throws Exception {
  4648. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4649. }
  4650. // //#include <iostream>
  4651. // using namespace std;
  4652. // template<class T> class Set {
  4653. // T* p;
  4654. // int cnt;
  4655. // public:
  4656. // Set();
  4657. // Set<T>(const Set<T>&);
  4658. // void printall()
  4659. // {
  4660. // for (int i = 0; i<cnt; i++)
  4661. // cout << p[i] << '\
  4662. // ';
  4663. // }
  4664. // // ...
  4665. // };
  4666. public void test14_6s8() throws Exception {
  4667. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4668. }
  4669. // void f(char);
  4670. // template<class T> void g(T t)
  4671. // {
  4672. // f(1); // f(char)
  4673. // f(T(1)); //dependent
  4674. // f(t); //dependent
  4675. // dd++; //not dependent
  4676. // // error: declaration for dd not found
  4677. // }
  4678. // void f(int);
  4679. // double dd;
  4680. // void h()
  4681. // {
  4682. // g(2); //will cause one call of f(char) followed
  4683. // // by two calls of f(int)
  4684. // g('a'); //will cause three calls of f(char)
  4685. // }
  4686. public void test14_6s9() throws Exception {
  4687. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4688. }
  4689. // template<class T, T* p, class U = T> class X { };
  4690. // template<class T> void f(T* p = new T);
  4691. public void test14_6_1s3a() throws Exception {
  4692. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4693. }
  4694. // template<class T> class X {
  4695. // X* p; // meaning X<T>
  4696. // X<T>* p2;
  4697. // X<int>* p3;
  4698. // };
  4699. public void test14_6_1s1() throws Exception {
  4700. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4701. }
  4702. // template<class T> class Y;
  4703. // template<> class Y<int> {
  4704. // Y* p; // meaning Y<int>
  4705. // Y<char>* q; // meaning Y<char>
  4706. // };
  4707. public void test14_6_1s2() throws Exception {
  4708. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4709. }
  4710. // template<typename T> class Array {};
  4711. // template<class T> class X : public Array<T> { };
  4712. // template<class T> class Y : public T { };
  4713. public void test14_6_1s3b() throws Exception {
  4714. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4715. }
  4716. // template<class T, int i> class Y {
  4717. // int T; // error: templateparameter redeclared
  4718. // void f() {
  4719. // char T; // error: templateparameter redeclared
  4720. // }
  4721. // };
  4722. // template<class X> class X; // error: templateparameter redeclared
  4723. public void test14_6_1s4() throws Exception {
  4724. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4725. }
  4726. // template<class T> struct A {
  4727. // struct B { };
  4728. // void f();
  4729. // };
  4730. // template<class B> void A<B>::f() {
  4731. // B b; // A's B, not the template parameter
  4732. // }
  4733. public void test14_6_1s5() throws Exception {
  4734. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4735. }
  4736. // namespace N {
  4737. // int C;
  4738. // template<class T> class B {
  4739. // void f(T);
  4740. // };
  4741. // }
  4742. // template<class C> void N::B<C>::f(C) {
  4743. // C b; // C is the template parameter, not N::C
  4744. // }
  4745. public void test14_6_1s6() throws Exception {
  4746. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4747. }
  4748. // struct A {
  4749. // struct B { };
  4750. // int a;
  4751. // int Y;
  4752. // };
  4753. // template<class B, class a> struct X : A {
  4754. // B b; // A's B
  4755. // a b; // error: A's a isn't a type name
  4756. // };
  4757. public void test14_6_1s7() throws Exception {
  4758. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4759. }
  4760. // template <typename T> class B {};
  4761. // template<class T> struct X : B<T> {
  4762. // typename T::A* pa;
  4763. // void f(B<T>* pb) {
  4764. // static int i = B<T>::i;
  4765. // pb->j++;
  4766. // }
  4767. // };
  4768. public void test14_6_2s2() throws Exception {
  4769. final String code = getAboveComment();
  4770. parse(code, ParserLanguage.CPP, true, 0);
  4771. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  4772. ICPPUnknownBinding unknown= bh.assertNonProblem("B<T>", 4);
  4773. unknown= bh.assertNonProblem("T::A", 4);
  4774. unknown= bh.assertNonProblem("B<T>::i", 7);
  4775. unknown= bh.assertNonProblem("j", 1);
  4776. }
  4777. // typedef double A;
  4778. // template<class T> class B {
  4779. // typedef int A;
  4780. // };
  4781. // template<class T> struct X : B<T> {
  4782. // A a; // a has type double
  4783. // };
  4784. public void test14_6_2s3() throws Exception {
  4785. final String content= getAboveComment();
  4786. IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
  4787. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  4788. IVariable v= bh.assertNonProblem("a;", 1);
  4789. IType t= v.getType();
  4790. assertInstance(t, ITypedef.class);
  4791. t= ((ITypedef) t).getType();
  4792. assertInstance(t, IBasicType.class);
  4793. assertEquals(IBasicType.t_double, ((IBasicType) t).getType());
  4794. }
  4795. // struct A {
  4796. // struct B { };
  4797. // int a;
  4798. // int Y;
  4799. // };
  4800. // int a;
  4801. // template<class T> struct Y : T {
  4802. // struct B { };
  4803. // B b; // The B defined in Y
  4804. // void f(int i) { a = i; } // ::a
  4805. // Y* p; // Y<T>
  4806. // };
  4807. // Y<A> ya;
  4808. public void test14_6_2s4() throws Exception {
  4809. final String content= getAboveComment();
  4810. parse(content, ParserLanguage.CPP, true, 0);
  4811. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  4812. IBinding b= bh.assertNonProblem("b;", 1);
  4813. assertEquals("Y", b.getOwner().getName());
  4814. b= bh.assertNonProblem("a = i", 1);
  4815. assertNull(b.getOwner());
  4816. }
  4817. // void g(double);
  4818. // void h();
  4819. // template<class T> class Z {
  4820. // public:
  4821. // void f() {
  4822. // g(1); //calls g(double)
  4823. // h++; //illformed:
  4824. // // cannot increment function;
  4825. // // this could be diagnosed either here or
  4826. // // at the point of instantiation
  4827. // }
  4828. // };
  4829. // void g(int); // not in scope at the point of the template
  4830. // // definition, not considered for the call g(1)
  4831. public void test14_6_3s1() throws Exception {
  4832. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4833. }
  4834. // template<typename T> class number {
  4835. // number(int);
  4836. // //...
  4837. // friend number gcd(number& x, number& y) { }
  4838. // //...
  4839. // };
  4840. // void g()
  4841. // {
  4842. // number<double> a(3), b(4);
  4843. // //...
  4844. // a = gcd(a,b); // finds gcd because number<double> is an
  4845. // // associated class, making gcd visible
  4846. // // in its namespace (global scope)
  4847. // b = gcd(3,4); // illformed; gcd is not visible
  4848. // }
  4849. public void test14_6_5s2() throws Exception {
  4850. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4851. }
  4852. // template<class T> class X {
  4853. // static T s;
  4854. // // ...
  4855. // };
  4856. // template<class T> T X<T>::s = 0;
  4857. // X<int> aa;
  4858. // X<char*> bb;
  4859. public void test14_7s6() throws Exception {
  4860. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4861. }
  4862. // template<class T> class Z {
  4863. // public:
  4864. // void f();
  4865. // void g();
  4866. // };
  4867. // void h()
  4868. // {
  4869. // Z<int> a; // instantiation of class Z<int> required
  4870. // Z<char>* p; // instantiation of class Z<char> not
  4871. // // required
  4872. // Z<double>* q; // instantiation of class Z<double>
  4873. // // not required
  4874. // a.f(); //instantiation of Z<int>::f() required
  4875. // p->g(); //instantiation of class Z<char> required, and
  4876. // // instantiation of Z<char>::g() required
  4877. // }
  4878. public void test14_7_1s3() throws Exception {
  4879. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4880. }
  4881. // template<class T> class B { };
  4882. // template<class T> class D : public B<T> { };
  4883. // void f(void*);
  4884. // void f(B<int>*);
  4885. // void g(D<int>* p, D<char>* pp, D<double> ppp)
  4886. // {
  4887. // f(p); //instantiation of D<int> required: call f(B<int>*)
  4888. // B<char>* q = pp; // instantiation of D<char> required:
  4889. // // convert D<char>* to B<char>*
  4890. // delete ppp; // instantiation of D<double> required
  4891. // }
  4892. public void test14_7_1s4() throws Exception {
  4893. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4894. }
  4895. // template<class T> class X;
  4896. // X<char> ch; // error: definition of X required
  4897. public void test14_7_1s6() throws Exception {
  4898. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4899. }
  4900. // template<class T = int> struct A {
  4901. // static int x;
  4902. // };
  4903. // template<class U> void g(U) { }
  4904. // template<> struct A<double> { }; // specialize for T == double
  4905. // template<> struct A<> { }; // specialize for T == int
  4906. // template<> void g(char) { } // specialize for U == char
  4907. // // U is deduced from the parameter type
  4908. // template<> void g<int>(int) { } // specialize for U == int
  4909. // template<> int A<char>::x = 0; // specialize for T == char
  4910. // template<class T = int> struct B {
  4911. // static int x;
  4912. // };
  4913. // template<> int B<>::x = 1; // specialize for T == int
  4914. public void test14_7s3() throws Exception {
  4915. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4916. }
  4917. // template <class T> struct S {
  4918. // operator int();
  4919. // };
  4920. // void f(int);
  4921. // void f(S<int>&);
  4922. // void f(S<float>);
  4923. // void g(S<int>& sr) {
  4924. // f(sr); //instantiation of S<int> allowed but not required
  4925. // // instantiation of S<float> allowed but not required
  4926. // };
  4927. public void test14_7_1s5() throws Exception {
  4928. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4929. }
  4930. // namespace N {
  4931. // template<class T> class List {
  4932. // public:
  4933. // T* get();
  4934. // // ...
  4935. // };
  4936. // }
  4937. // template<class K, class V> class Map {
  4938. // N::List<V> lt;
  4939. // V get(K);
  4940. // // ...
  4941. // };
  4942. // void g(Map<char*,int>& m)
  4943. // {
  4944. // int i = m.get("Nicholas");
  4945. // // ...
  4946. // }
  4947. public void test14_7_1s10() throws Exception {
  4948. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4949. }
  4950. // template<class T> void f(T x, T y = ydef(T()), T z = zdef(T()));
  4951. // class A { };
  4952. // A zdef(A);
  4953. // void g(A a, A b, A c) {
  4954. // f(a, b, c); // no default argument instantiation
  4955. // f(a, b); // default argument z = zdef(T()) instantiated
  4956. // f(a); //illformed; ydef is not declared
  4957. // }
  4958. public void test14_7_1s12() throws Exception {
  4959. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4960. }
  4961. // template<class T> class X {
  4962. // X<T>* p; // OK
  4963. // X<T*> a; // implicit generation of X<T> requires
  4964. // // the implicit instantiation of X<T*> which requires
  4965. // // the implicit instantiation of X<T**> which ...
  4966. // };
  4967. public void test14_7_1s14() throws Exception {
  4968. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4969. }
  4970. // template<class T> class Array { void mf(); };
  4971. // template class Array<char>;
  4972. // template void Array<int>::mf();
  4973. // template<class T> void sort(Array<T>& v) { }
  4974. // template void sort(Array<char>&); // argument is deduced here
  4975. // namespace N {
  4976. // template<class T> void f(T&) { }
  4977. // }
  4978. // template void N::f<int>(int&);
  4979. public void test14_7_2s2() throws Exception {
  4980. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  4981. }
  4982. // namespace N {
  4983. // template<class T> class Y { void mf() { } };
  4984. // }
  4985. // template class Y<int>; // error: class template Y not visible
  4986. // // in the global namespace
  4987. // using N::Y;
  4988. // template class Y<int>; // OK: explicit instantiation in namespace N
  4989. // template class N::Y<char*>; // OK: explicit instantiation in namespace N
  4990. // template void N::Y<double>::mf(); // OK: explicit instantiation
  4991. // // in namespace N
  4992. public void test14_7_2s5() throws Exception {
  4993. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  4994. }
  4995. // template<class T> class Array { };
  4996. // template<class T> void sort(Array<T>& v);
  4997. // // instantiate sort(Array<int>&) - templateargument deduced
  4998. // template void sort<>(Array<int>&);
  4999. public void test14_7_2s6() throws Exception {
  5000. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5001. }
  5002. // char* p = 0;
  5003. // template<class T> T g(T = &p);
  5004. // template int g<int>(int); // OK even though &p isn't an int.
  5005. public void test14_7_2s9() throws Exception {
  5006. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5007. }
  5008. // template<class T> class stream;
  5009. // template<> class stream<char> { };
  5010. // template<class T> class Array { };
  5011. // template<class T> void sort(Array<T>& v) { }
  5012. // template<> void sort<char*>(Array<char*>&) ;
  5013. public void test14_7_3s1() throws Exception {
  5014. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5015. }
  5016. // template<> class X<int> { }; // error: X not a template
  5017. // template<class T> class X;
  5018. // template<> class X<char*> { }; // OK: X is a template
  5019. public void test14_7_3s3() throws Exception {
  5020. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5021. }
  5022. // template<class T> struct A {
  5023. // void f(T) { }
  5024. // };
  5025. // template<> struct A<int> {
  5026. // void f(int);
  5027. // };
  5028. // void h()
  5029. // {
  5030. // A<int> a;
  5031. // a.f(16); // A<int>::f must be defined somewhere
  5032. // }
  5033. // // explicit specialization syntax not used for a member of
  5034. // // explicitly specialized class template specialization
  5035. // void A<int>::f(int) { }
  5036. public void test14_7_3s5() throws Exception {
  5037. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5038. }
  5039. // template<class T> class Array { };
  5040. // template<class T> void sort(Array<T>& v) { }
  5041. // void f(Array<String>& v)
  5042. // {
  5043. // sort(v); //use primary template
  5044. // // sort(Array<T>&), T is String
  5045. // }
  5046. // template<> void sort<String>(Array<String>& v); // error: specialization
  5047. // // after use of primary template
  5048. // template<> void sort<>(Array<char*>& v); // OK: sort<char*> not yet used
  5049. public void test14_7_3s6() throws Exception {
  5050. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5051. }
  5052. // namespace N {
  5053. // template<class T> class X { };
  5054. // template<class T> class Y { };
  5055. // template<> class X<int> { }; // OK: specialization
  5056. // // in same namespace
  5057. // template<> class Y<double>; // forward declare intent to
  5058. // // specialize for double
  5059. // }
  5060. // template<> class N::Y<double> { }; // OK: specialization
  5061. // // in same namespace
  5062. public void test14_7_3s9() throws Exception {
  5063. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5064. }
  5065. // template<class T> class Array { };
  5066. // template<class T> void sort(Array<T>& v);
  5067. // // explicit specialization for sort(Array<int>&)
  5068. // // with deduces templateargument of type int
  5069. // template<> void sort(Array<int>&);
  5070. public void test14_7_3s11() throws Exception {
  5071. parse(getAboveComment(), ParserLanguage.CPP, true, 0 );
  5072. }
  5073. // template<class T1> class A {
  5074. // template<class T2> class B {
  5075. // void mf();
  5076. // };
  5077. // };
  5078. // template<> template<> class A<int>::B<double> { };
  5079. // template<> template<> void A<char>::B<char>::mf() { };
  5080. public void test14_7_3s17() throws Exception {
  5081. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5082. }
  5083. // template<class T> class X; // X is a class template
  5084. // template<> class X<int>;
  5085. // X<int>* p; // OK: pointer to declared class X<int>
  5086. // X<int> x; // error: object of incomplete class X<int>
  5087. public void test14_7_3s10() throws Exception {
  5088. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5089. }
  5090. // template <class T> void f(T);
  5091. // template <class T> void f(T*);
  5092. // template <> void f(int*); // Ambiguous
  5093. // template <> void f<int>(int*); // OK
  5094. // template <> void f(int); // OK
  5095. public void test14_7_3s12() throws Exception {
  5096. // gcc does not report the explicit instantiation as ambiguous, so we accept it as well.
  5097. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5098. }
  5099. // template<class T> void f(T) { }
  5100. // template<class T> inline T g(T) { }
  5101. // template<> inline void f<>(int) { } // OK: inline
  5102. // template<> int g<>(int) { } // OK: not inline
  5103. public void test14_7_3s14() throws Exception {
  5104. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5105. }
  5106. // template<class T> struct A {
  5107. // void f(T);
  5108. // template<class X> void g(T,X);
  5109. // void h(T) { }
  5110. // };
  5111. // // specialization
  5112. // template<> void A<int>::f(int);
  5113. // // out of class member template definition
  5114. // template<class T> template<class X> void A<T>::g(T,X) { }
  5115. // // member template partial specialization
  5116. // template<> template<class X> void A<int>::g(int,X);
  5117. // // member template specialization
  5118. // template<> template<>
  5119. // void A<int>::g(int,char); // X deduced as char
  5120. // template<> template<>
  5121. // void A<int>::g<char>(int,char); // X specified as char
  5122. // // member specialization even if defined in class definition
  5123. // template<> void A<int>::h(int) { }
  5124. public void test14_7_3s16() throws Exception {
  5125. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5126. }
  5127. // template<class T1> class A {
  5128. // template<class T2> class B {
  5129. // template<class T3> void mf1(T3);
  5130. // void mf2();
  5131. // };
  5132. // };
  5133. // template<> template<class X>
  5134. // class A<int>::B { };
  5135. // template<> template<> template<class T>
  5136. // void A<int>::B<double>::mf1(T t) { };
  5137. // template<class Y> template<>
  5138. // void A<Y>::B<double>::mf2() { }; // illformed; B<double> is specialized but
  5139. // // its enclosing class template A is not
  5140. public void test14_7_3s18() throws Exception {
  5141. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5142. }
  5143. // template<class T> void f(T* p)
  5144. // {
  5145. // static T s;
  5146. // // ...
  5147. // };
  5148. // void g(int a, char* b)
  5149. // {
  5150. // f(&a); //call f<int>(int*)
  5151. // f(&b); //call f<char*>(char**)
  5152. // }
  5153. public void test14_8s2() throws Exception {
  5154. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5155. }
  5156. // template<class T> void sort(Array<T>& v);
  5157. // void f(Array<dcomplex>& cv, Array<int>& ci)
  5158. // {
  5159. // sort<dcomplex>(cv); // sort(Array<dcomplex>&)
  5160. // sort<int>(ci); // sort(Array<int>&)
  5161. // }
  5162. // template<class U, class V> U convert(V v);
  5163. // void g(double d)
  5164. // {
  5165. // int i = convert<int,double>(d); // int convert(double)
  5166. // char c = convert<char,double>(d); // char convert(double)
  5167. // }
  5168. public void test14_8_1s1() throws Exception {
  5169. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5170. }
  5171. // template<class X, class Y> X f(Y);
  5172. // void g()
  5173. // {
  5174. // int i = f<int>(5.6); // Y is deduced to be double
  5175. // int j = f(5.6); // illformed: X cannot be deduced
  5176. // }
  5177. public void test14_8_1s2() throws Exception {
  5178. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5179. }
  5180. // template<class X, class Y, class Z> X f(Y,Z);
  5181. // void g()
  5182. // {
  5183. // f<int,char*,double>("aa",3.0);
  5184. // f<int,char*>("aa",3.0); // Z is deduced to be double
  5185. // f<int>("aa",3.0); // Y is deduced to be char*, and
  5186. // // Z is deduced to be double
  5187. // f("aa",3.0); //error: X cannot be deduced
  5188. // }
  5189. public void test14_8_1s3() throws Exception {
  5190. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5191. }
  5192. // template<class T> void f(T);
  5193. // class Complex {
  5194. // // ...
  5195. // Complex(double);
  5196. // };
  5197. // void g()
  5198. // {
  5199. // f<Complex>(1); // OK, means f<Complex>(Complex(1))
  5200. // }
  5201. public void test14_8_1s4() throws Exception {
  5202. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5203. }
  5204. // namespace A {
  5205. // struct B { };
  5206. // template<int X> void f();
  5207. // }
  5208. // namespace C {
  5209. // template<class T> void f(T t);
  5210. // }
  5211. // void g(A::B b) {
  5212. // f<3>(b); //illformed: not a function call
  5213. // A::f<3>(b); //wellformed
  5214. // C::f<3>(b); //illformed; argument dependent lookup
  5215. // // only applies to unqualified names
  5216. // using C::f;
  5217. // f<3>(b); //wellformed because C::f is visible; then
  5218. // // A::f is found by argument dependent lookup
  5219. // }
  5220. public void test14_8_1s6() throws Exception {
  5221. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5222. }
  5223. // void f(Array<dcomplex>& cv, Array<int>& ci)
  5224. // {
  5225. // sort(cv); //call sort(Array<dcomplex>&)
  5226. // sort(ci); //call sort(Array<int>&)
  5227. // }
  5228. // void g(double d)
  5229. // {
  5230. // int i = convert<int>(d); // call convert<int,double>(double)
  5231. // int c = convert<char>(d); // call convert<char,double>(double)
  5232. // }
  5233. public void test14_8_2s1() throws Exception {
  5234. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5235. }
  5236. // template <class T> void f(T t);
  5237. // template <class X> void g(const X x);
  5238. // template <class Z> void h(Z, Z*);
  5239. // int main()
  5240. // {
  5241. // // #1: function type is f(int), t is nonconst
  5242. // f<int>(1);
  5243. // // #2: function type is f(int), t is const
  5244. // f<const int>(1);
  5245. // // #3: function type is g(int), x is const
  5246. // g<int>(1);
  5247. // // #4: function type is g(int), x is const
  5248. // g<const int>(1);
  5249. // // #5: function type is h(int, const int*)
  5250. // h<const int>(1,0);
  5251. // }
  5252. public void test14_8_2s3() throws Exception {
  5253. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5254. }
  5255. // template <class T, class U = double>
  5256. // void f(T t = 0, U u = 0);
  5257. // void g() {
  5258. // f(1, 'c'); // f<int,char>(1,'c')
  5259. // f(1); // f<int,double>(1,0)
  5260. // f(); // error: T cannot be deduced
  5261. // f<int>(); // f<int,double>(0,0)
  5262. // f<int,char>(); // f<int,char>(0,0)
  5263. // }
  5264. public void test14_8_2s5() throws Exception {
  5265. final String content= getAboveComment();
  5266. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  5267. ICPPTemplateInstance inst;
  5268. inst= bh.assertNonProblem("f(1, 'c')", 1);
  5269. assertEquals("<int,char>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5270. inst= bh.assertNonProblem("f(1)", 1);
  5271. assertEquals("<int,double>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5272. bh.assertProblem("f()", 1);
  5273. inst= bh.assertNonProblem("f<int>()", -2);
  5274. assertEquals("<int,double>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5275. inst= bh.assertNonProblem("f<int,char>()", -2);
  5276. assertEquals("<int,char>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5277. }
  5278. // struct X { };
  5279. // struct Y {
  5280. // Y(X){}
  5281. // };
  5282. // template <class T> auto f(T t1, T t2) -> decltype(t1 + t2); // #1
  5283. // X f(Y, Y); // #2
  5284. // X x1, x2;
  5285. // X x3 = f(x1, x2); // deduction fails on #1 (cannot add X+X), calls #2
  5286. public void test14_8_2s8a() throws Exception {
  5287. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5288. }
  5289. // template <class T> int f(T[5]);
  5290. // int I = f<int>(0);
  5291. // int j = f<void>(0); // invalid array // also no error with gcc
  5292. public void _test14_8_2s8b() throws Exception {
  5293. final String content= getAboveComment();
  5294. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  5295. bh.assertNonProblem("f<int>(0)", -3);
  5296. bh.assertProblem("f<void>(0)", -3);
  5297. }
  5298. // template <class T> int f(typename T::B*);
  5299. // int i = f<int>(0);
  5300. public void test14_8_2s8c() throws Exception {
  5301. final String content= getAboveComment();
  5302. IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 2);
  5303. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  5304. bh.assertProblem("f<", 1);
  5305. bh.assertProblem("f<int>", 6);
  5306. }
  5307. // template <int I> struct X { };
  5308. // template <template <class T> class> struct Z { };
  5309. // template <class T> void f(typename T::Y*){}
  5310. // template <class T> void g(X<T::N>*){}
  5311. // template <class T> void h(Z<T::template TT>*){}
  5312. // struct A {};
  5313. // struct B { int Y; };
  5314. // struct C {
  5315. // typedef int N;
  5316. // };
  5317. // struct D {
  5318. // typedef int TT;
  5319. // };
  5320. // int main() {
  5321. // // Deduction fails in each of these cases:
  5322. // f<A>(0); // A does not contain a member Y
  5323. // f<B>(0); // The Y member of B is not a type
  5324. // g<C>(0); // The N member of C is not a non-type
  5325. // h<D>(0); // The TT member of D is not a template
  5326. // }
  5327. public void _test14_8_2s8d() throws Exception {
  5328. final String content= getAboveComment();
  5329. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  5330. bh.assertProblem("f<A>", 0);
  5331. bh.assertProblem("f<B>", 0);
  5332. bh.assertProblem("g<C>", 0);
  5333. bh.assertProblem("h<D>", 0);
  5334. }
  5335. // template <class T> int f(int T::*);
  5336. // int i = f<int>(0);
  5337. public void test14_8_2s8e() throws Exception {
  5338. final String code = getAboveComment();
  5339. parse(code, ParserLanguage.CPP, true, 2);
  5340. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5341. bh.assertProblem("f<int>", 0);
  5342. }
  5343. // template <class T, T> struct S {};
  5344. // template <class T> int f(S<T, T()>*);
  5345. // struct X {};
  5346. // int i0 = f<X>(0);
  5347. public void test14_8_2s8f() throws Exception {
  5348. final String code = getAboveComment();
  5349. parse(code, ParserLanguage.CPP, true, 2);
  5350. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5351. bh.assertProblem("f<X>", 0);
  5352. }
  5353. // template <class T, T*> int f(int);
  5354. // int i2 = f<int,1>(0); // can't conv 1 to int*
  5355. public void test14_8_2s8g() throws Exception {
  5356. parse(getAboveComment(), ParserLanguage.CPP, false, 1);
  5357. }
  5358. // template <int> int f(int);
  5359. // template <signed char> int f(int);
  5360. // int i1 = f<1>(0); // ambiguous
  5361. // int i2 = f<1000>(0); // ambiguous
  5362. public void test14_8_2s9() throws Exception {
  5363. parse(getAboveComment(), ParserLanguage.CPP, false, 2);
  5364. }
  5365. // namespace std {
  5366. // template<typename T> class initializer_list;
  5367. // }
  5368. // template<class T> void f(std::initializer_list<T>);
  5369. // template<class T> void g(T);
  5370. // void test() {
  5371. // f({1,2,3}); // T deduced to int
  5372. // f({1,"asdf"}); // error: T deduced to both int and const char*
  5373. // g({1,2,3}); // error: no argument deduced for T
  5374. // }
  5375. public void test14_8_2_1s1a() throws Exception {
  5376. final String code= getAboveComment();
  5377. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5378. ICPPTemplateInstance inst;
  5379. inst= bh.assertNonProblem("f({1,2,3})", 1);
  5380. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5381. bh.assertProblem("f({1,\"asdf\"})", 1);
  5382. bh.assertProblem("g({1,2,3})", 1);
  5383. }
  5384. // template<class ... Types> void f(Types& ...);
  5385. // template<class T1, class ... Types> void g(T1, Types ...);
  5386. // void h(int x, float& y) {
  5387. // const int z = x;
  5388. // f(x, y, z); // Types is deduced to int, float, const int
  5389. // g(x, y, z); // T1 is deduced to int; Types is deduced to float, int
  5390. // }
  5391. public void test14_8_2_1s1b() throws Exception {
  5392. final String code= getAboveComment();
  5393. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5394. ICPPTemplateInstance inst;
  5395. inst= bh.assertNonProblem("f(x, y, z)", 1);
  5396. assertEquals("<int,float,const int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5397. inst= bh.assertNonProblem("g(x, y, z)", 1);
  5398. assertEquals("<int,float,int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5399. }
  5400. // template <class T> int f(T&&);
  5401. // template <class T> int g(const T&&);
  5402. // int i;
  5403. // int n1 = f(i); // calls f<int&>(int&)
  5404. // int n2 = f(0); // calls f<int>(int&&)
  5405. // int n3 = g(i); // error: would call g<int>(const int&&), which
  5406. // // would bind an rvalue reference to an lvalue
  5407. public void test14_8_2_1s3() throws Exception {
  5408. final String code= getAboveComment();
  5409. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5410. ICPPTemplateInstance inst;
  5411. inst= bh.assertNonProblem("f(i)", 1);
  5412. assertEquals("<int &>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5413. inst= bh.assertNonProblem("f(0)", 1);
  5414. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5415. bh.assertProblem("g(i)", 1);
  5416. }
  5417. // // Only one function of an overload set matches the call so the function
  5418. // // parameter is a deduced context.
  5419. // template <class T> int f(T (*p)(T));
  5420. // int g(int);
  5421. // int g(char);
  5422. // int i = f(g); // calls f(int (*)(int))
  5423. public void test14_8_2_1s7() throws Exception {
  5424. final String code= getAboveComment();
  5425. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5426. ICPPTemplateInstance inst;
  5427. inst= bh.assertNonProblem("f(g)", 1);
  5428. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5429. }
  5430. // // Ambiguous deduction causes the second function parameter to be a
  5431. // // non-deduced context.
  5432. // template <class T> int f(T, T (*p)(T));
  5433. // int g(int);
  5434. // char g(char);
  5435. // int i = f(1, g); // calls f(int, int (*)(int))
  5436. public void test14_8_2_1s8() throws Exception {
  5437. final String code= getAboveComment();
  5438. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5439. ICPPTemplateInstance inst;
  5440. inst= bh.assertNonProblem("f(1, g)", 1);
  5441. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5442. }
  5443. // // The overload set contains a template, causing the second function
  5444. // // parameter to be a non-deduced context.
  5445. // template <class T> int f(T, T (*p)(T));
  5446. // char g(char);
  5447. // template <class T> T g(T);
  5448. // int i = f(1, g); // calls f(int, int (*)(int))
  5449. public void test14_8_2_1s9() throws Exception {
  5450. final String code= getAboveComment();
  5451. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5452. ICPPTemplateInstance inst;
  5453. inst= bh.assertNonProblem("f(1, g)", 1);
  5454. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5455. }
  5456. // struct A {
  5457. // template <class T> operator T***();
  5458. // };
  5459. // A a;
  5460. // void test(const int * const * const * p1) {
  5461. // test(a); // T is deduced as int, not const int
  5462. // }
  5463. public void test14_8_2_3s7() throws Exception {
  5464. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5465. }
  5466. // template <class T> T f(int); // #1
  5467. // template <class T, class U> T f(U); // #2
  5468. // void g() {
  5469. // f<int>(1); // calls #1
  5470. // }
  5471. public void test14_8_2_4s11() throws Exception {
  5472. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5473. }
  5474. // template<typename...> struct Tuple { };
  5475. // template<typename... Types> void g(Tuple<Types...>); // #1
  5476. // template<typename T1, typename... Types> void g(Tuple<T1, Types...>); // #2
  5477. // template<typename T1, typename... Types> void g(Tuple<T1, Types&...>); // #3
  5478. // void test() {
  5479. // g(Tuple<>()); // calls #1
  5480. // g(Tuple<int, float>()); // calls #2
  5481. // g(Tuple<int, float&>()); // calls #3
  5482. // g(Tuple<int>()); // calls #3
  5483. // }
  5484. public void test14_8_2_4s12() throws Exception {
  5485. final String code= getAboveComment();
  5486. parse(code, ParserLanguage.CPP, true, 0);
  5487. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5488. ICPPFunction g1= bh.assertNonProblem("g(Tuple<Types...>)", 1);
  5489. ICPPFunction g2= bh.assertNonProblem("g(Tuple<T1, Types...>)", 1);
  5490. ICPPFunction g3= bh.assertNonProblem("g(Tuple<T1, Types&...>)", 1);
  5491. ICPPTemplateInstance x= bh.assertNonProblem("g(Tuple<>())", 1);
  5492. assertSame(g1, x.getTemplateDefinition());
  5493. x= bh.assertNonProblem("g(Tuple<int, float>())", 1);
  5494. assertSame(g2, x.getTemplateDefinition());
  5495. x= bh.assertNonProblem("g(Tuple<int, float&>())", 1);
  5496. assertSame(g3, x.getTemplateDefinition());
  5497. x= bh.assertNonProblem("g(Tuple<int>())", 1);
  5498. assertSame(g3, x.getTemplateDefinition());
  5499. }
  5500. // template<class T> void g(T);
  5501. // void test() {
  5502. // g({1,2,3}); // error: no argument deduced for T
  5503. // }
  5504. public void test14_8_2_5s5() throws Exception {
  5505. final String code= getAboveComment();
  5506. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5507. bh.assertProblem("g({1,2,3})", 1);
  5508. }
  5509. // template<class T> void f(T x, T y) { }
  5510. // struct A { };
  5511. // struct B : A { };
  5512. // int g(A a, B b)
  5513. // {
  5514. // f(a,b); //error: T could be A or B
  5515. // f(b,a); //error: T could be A or B
  5516. // f(a,a); //OK: T is A
  5517. // f(b,b); //OK: T is B
  5518. // }
  5519. public void test14_8_2_5s7a() throws Exception {
  5520. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5521. }
  5522. // template <class T, class U> void f( T (*)( T, U, U ) );
  5523. // int g1( int, float, float);
  5524. // char g2( int, float, float);
  5525. // int g3( int, char, float);
  5526. // void r()
  5527. // {
  5528. // f(g1); //OK: T is int and U is float
  5529. // f(g2); //error: T could be char or int
  5530. // f(g3); //error: U could be char or float
  5531. // }
  5532. public void test14_8_2_5s7b() throws Exception {
  5533. final String code= getAboveComment();
  5534. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5535. ICPPTemplateInstance inst;
  5536. inst= bh.assertNonProblem("f(g1)", 1);
  5537. assertEquals("<int,float>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5538. bh.assertProblem("f(g2)", 1);
  5539. bh.assertProblem("f(g3)", 1);
  5540. }
  5541. // template<class T> void f(const T*) {}
  5542. // int *p;
  5543. // void s()
  5544. // {
  5545. // f(p); // f(const int *)
  5546. // }
  5547. public void test14_8_2_5s7c() throws Exception {
  5548. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5549. }
  5550. // template <class T> struct B { };
  5551. // template <class T> struct D : public B<T> {};
  5552. // struct D2 : public B<int> {};
  5553. // template <class T> void f(B<T>&){}
  5554. // void t()
  5555. // {
  5556. // D<int> d;
  5557. // D2 d2;
  5558. // f(d); //calls f(B<int>&)
  5559. // f(d2); //calls f(B<int>&)
  5560. // }
  5561. public void test14_8_2_5s7d() throws Exception {
  5562. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5563. }
  5564. // template <class T> void f(T&&);
  5565. // template <> void f(int&) { } // #1
  5566. // template <> void f(int&&) { } // #2
  5567. // void g(int i) {
  5568. // f(i); // calls f<int&>(int&), i.e., #1
  5569. // f(0); // calls f<int>(int&&), i.e., #2
  5570. // }
  5571. public void test14_8_2_5s10() throws Exception {
  5572. final String code= getAboveComment();
  5573. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5574. ICPPTemplateInstance inst;
  5575. inst= bh.assertNonProblem("f(i)", 1);
  5576. assertEquals("<int &>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5577. inst= bh.assertNonProblem("f(0)", 1);
  5578. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5579. }
  5580. // template<class T, T i> void f(double a[10][i]);
  5581. // int v[10][20];
  5582. // int foo() {
  5583. // f(v); //error: argument for templateparameter
  5584. // //T cannot be deduced
  5585. // }
  5586. public void test14_8_2_5s14() throws Exception {
  5587. final String code= getAboveComment();
  5588. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5589. bh.assertProblem("f(v)", 1);
  5590. }
  5591. // template<int i> void f1(int a[10][i]);
  5592. // template<int i> void f2(int a[i][20]);
  5593. // template<int i> void f3(int (&a)[i][20]);
  5594. // void g()
  5595. // {
  5596. // int v[10][20];
  5597. // f1(v); //OK: i deduced to be 20
  5598. // f1<20>(v); //OK
  5599. // f2(v); //error: cannot deduce templateargument i
  5600. // f2<10>(v); //OK
  5601. // f3(v); //OK: i deduced to be 10
  5602. // }
  5603. public void test14_8_2_5s15() throws Exception {
  5604. final String code= getAboveComment();
  5605. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5606. ICPPTemplateInstance inst;
  5607. inst= bh.assertNonProblem("f1(v)", 2);
  5608. assertEquals("<20>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5609. inst= bh.assertNonProblem("f1<20>(v)", -3);
  5610. assertEquals("<20>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5611. bh.assertProblem("f2(v)", 2);
  5612. inst= bh.assertNonProblem("f2<10>(v)", -3);
  5613. assertEquals("<10>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5614. inst= bh.assertNonProblem("f3(v)", 2);
  5615. assertEquals("<10>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5616. }
  5617. // template <int i> class A { };
  5618. // template <int i> void g(A<i+1>);
  5619. // template <int i> void f(A<i>, A<i+1>);
  5620. // void k() {
  5621. // A<1> a1;
  5622. // A<2> a2;
  5623. // g(a1); // error: deduction fails for expression i+1
  5624. // g<0>(a1); // OK
  5625. // f(a1, a2); // OK
  5626. // }
  5627. public void test14_8_2_5s16a() throws Exception {
  5628. final String code= getAboveComment();
  5629. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5630. ICPPTemplateInstance inst;
  5631. bh.assertProblem("g(a1)", 1);
  5632. inst= bh.assertNonProblem("g<0>(a1)", -4);
  5633. assertEquals("<0>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5634. inst= bh.assertNonProblem("f(a1, a2)", 1);
  5635. assertEquals("<1>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5636. }
  5637. // template<typename T> class A {
  5638. // public:
  5639. // typedef int X;
  5640. // X xm;
  5641. // };
  5642. // template<int I> class B {
  5643. // public:
  5644. // typedef int* Y;
  5645. // Y ym;
  5646. // };
  5647. // template<int i, typename T>
  5648. // T deduce(typename A<T>::X x, // T is not deduced here
  5649. // T t, // but T is deduced here
  5650. // typename B<i>::Y y); // i is not deduced here
  5651. // void test() {
  5652. // A<int> a;
  5653. // B<77> b;
  5654. // deduce<77> (a.xm, 62, b.ym);
  5655. // }
  5656. public void test14_8_2_5s16b() throws Exception {
  5657. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5658. }
  5659. // template<int i> class A {};
  5660. // template<short s> void f(A<s>);
  5661. // void k1() {
  5662. // A<1> a;
  5663. // f(a); // error: deduction fails for conversion from int to short
  5664. // f<1>(a); // OK
  5665. // }
  5666. // template<const short cs> class B { };
  5667. // template<short s> void g(B<s>);
  5668. // void k2() {
  5669. // B<1> b;
  5670. // g(b); // OK: cv-qualifiers are ignored on template parameter types
  5671. // }
  5672. public void test14_8_2_5s17() throws Exception {
  5673. final String code= getAboveComment();
  5674. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5675. ICPPTemplateInstance inst;
  5676. bh.assertProblem("f(a)", 1);
  5677. inst= bh.assertNonProblem("f<1>(a)", -3);
  5678. assertEquals("<1>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5679. inst= bh.assertNonProblem("g(b)", 1);
  5680. assertEquals("<1>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5681. }
  5682. // template<class T> void f(void(*)(T,int));
  5683. // template<class T> void foo(T,int);
  5684. // void g(int,int);
  5685. // void g(char,int);
  5686. // void h(int,int,int);
  5687. // void h(char,int);
  5688. // int m() {
  5689. // f(&g); // error: ambiguous
  5690. // f(&h); // OK: void h(char,int) is a unique match
  5691. // f(&foo); // error: type deduction fails because foo is a template
  5692. // }
  5693. public void test14_8_2_5s18() throws Exception {
  5694. final String code= getAboveComment();
  5695. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5696. ICPPTemplateInstance inst;
  5697. bh.assertProblem("f(&g)", 1);
  5698. inst= bh.assertNonProblem("f(&h)", 1);
  5699. assertEquals("<char>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5700. bh.assertProblem("f(&foo)", 1);
  5701. }
  5702. // template <class T> void f(T = 5, T = 7);
  5703. // void g() {
  5704. // f(1); // OK: call f<int>(1,7)
  5705. // f(); // error: cannot deduce T
  5706. // f<int>(); // OK: call f<int>(5,7)
  5707. // }
  5708. public void test14_8_2_5s19() throws Exception {
  5709. final String code= getAboveComment();
  5710. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5711. ICPPTemplateInstance inst;
  5712. inst= bh.assertNonProblem("f(1)", 1);
  5713. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5714. bh.assertProblem("f()", 1);
  5715. inst= bh.assertNonProblem("f<int>()", -2);
  5716. assertEquals("<int>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true));
  5717. }
  5718. // template <template <class T> class X> struct A { };
  5719. // template <template <class T> class X> void f(A<X>) { }
  5720. // template<class T> struct B { };
  5721. // int foo() {
  5722. // A<B> ab;
  5723. // f(ab); //calls f(A<B>)
  5724. // }
  5725. public void test14_8_2_4s20() throws Exception {
  5726. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5727. }
  5728. // template<class> struct X { };
  5729. // template<class R, class ... ArgTypes> struct X<R(int, ArgTypes ...)> { };
  5730. // template<class ... Types> struct Y { };
  5731. // template<class T, class ... Types> struct Y<T, Types& ...> { };
  5732. // template<class ... Types> int f(void (*)(Types ...));
  5733. // void g(int, float);
  5734. // X<int> x1; // uses primary template
  5735. // X<int(int, float, double)> x2; // uses partial specialization; ArgTypes contains float, double
  5736. // X<int(float, int)> x3; // uses primary template
  5737. // Y<> y1; // use primary template; Types is empty
  5738. // Y<int&, float&, double&> y2; // uses partial specialization; T is int&, Types contains float, double
  5739. // Y<int, float, double> y3; // uses primary template; Types contains int, float, double
  5740. // int fv = f(g); // OK; Types contains int, float
  5741. public void test14_8_2_4s21() throws Exception {
  5742. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5743. }
  5744. // template<class ... Args> void f(Args ... args); // #1
  5745. // template<class T1, class ... Args> void f(T1 a1, Args ... args); // #2
  5746. // template<class T1, class T2> void f(T1 a1, T2 a2); // #3
  5747. // void test() {
  5748. // f(); // calls #1
  5749. // f(1, 2, 3); // calls #2
  5750. // f(1, 2); // calls #3; non-variadic template #3 is more
  5751. // // specialized than the variadic templates #1 and #2
  5752. // }
  5753. public void test14_8_2_5s22() throws Exception {
  5754. final String code= getAboveComment();
  5755. BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
  5756. ICPPFunctionTemplate f1= bh.assertNonProblem("f(Args ... args)", 1);
  5757. ICPPFunctionTemplate f2= bh.assertNonProblem("f(T1 a1, Args ... args)", 1);
  5758. ICPPFunctionTemplate f3= bh.assertNonProblem("f(T1 a1, T2 a2)", 1);
  5759. ICPPTemplateInstance inst;
  5760. inst= bh.assertNonProblem("f()", 1);
  5761. assertSame(f1, inst.getTemplateDefinition());
  5762. inst= bh.assertNonProblem("f(1, 2, 3)", 1);
  5763. assertSame(f2, inst.getTemplateDefinition());
  5764. inst= bh.assertNonProblem("f(1, 2)", 1);
  5765. assertSame(f3, inst.getTemplateDefinition());
  5766. }
  5767. // template<class T> T max(T a, T b) { return a>b?a:b; }
  5768. // void f(int a, int b, char c, char d)
  5769. // {
  5770. // int m1 = max(a,b); // max(int a, int b)
  5771. // char m2 = max(c,d); // max(char a, char b)
  5772. // int m3 = max(a,c); // error: cannot generate max(int,char)
  5773. // }
  5774. public void test14_8_3s2() throws Exception {
  5775. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5776. }
  5777. // template<class T> T max(T a, T b) { return a>b?a:b; }
  5778. // int max(int,int);
  5779. // void f(int a, int b, char c, char d)
  5780. // {
  5781. // int m1 = max(a,b); // max(int a, int b)
  5782. // char m2 = max(c,d); // max(char a, char b)
  5783. // int m3 = max(a,c); // resolved
  5784. // }
  5785. public void test14_8_3s3() throws Exception {
  5786. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5787. }
  5788. // template<class T> struct B { };
  5789. // template<class T> struct D : public B<T> { };
  5790. // template<class T> void f(B<T>&);
  5791. // void g(B<int>& bi, D<int>& di)
  5792. // {
  5793. // f(bi); // f(bi)
  5794. // f(di); // f( (B<int>&)di )
  5795. // }
  5796. public void test14_8_3s4() throws Exception {
  5797. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5798. }
  5799. // template<class T> void f(T*,int); // #1
  5800. // template<class T> void f(T,char); // #2
  5801. // void h(int* pi, int i, char c)
  5802. // {
  5803. // f(pi,i); //#1: f<int>(pi,i)
  5804. // f(pi,c); //#2: f<int*>(pi,c)
  5805. // f(i,c); //#2: f<int>(i,c);
  5806. // f(i,i); //#2: f<int>(i,char(i))
  5807. // }
  5808. public void test14_8_3s5() throws Exception {
  5809. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5810. }
  5811. // template<class T> void f(T); // declaration
  5812. // void g() {
  5813. // f("Annemarie"); // call of f<const char*>
  5814. // }
  5815. public void test14_8_3s6() throws Exception {
  5816. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5817. }
  5818. // int foo() {
  5819. // lab: try {
  5820. // int t1;
  5821. // try {
  5822. // int t2;
  5823. // if (1)
  5824. // goto lab;
  5825. // } catch(...) { // handler 2
  5826. // }
  5827. // } catch(...) { // handler 1
  5828. // }
  5829. // }
  5830. public void test15s2() throws Exception {
  5831. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5832. }
  5833. // int f(int);
  5834. // class C {
  5835. // int i;
  5836. // double d;
  5837. // public:
  5838. // C(int, double);
  5839. // };
  5840. // C::C(int ii, double id)
  5841. // try
  5842. // : i(f(ii)), d(id)
  5843. // {
  5844. // // constructor function body
  5845. // }
  5846. // catch (...)
  5847. // {
  5848. // // handles exceptions thrown from the ctorinitializer
  5849. // // and from the constructor function body
  5850. // }
  5851. public void test15s3() throws Exception {
  5852. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5853. }
  5854. // class Overflow {
  5855. // // ...
  5856. // public:
  5857. // Overflow(char,double,double);
  5858. // };
  5859. // void f(double x)
  5860. // {
  5861. // // ...
  5862. // throw Overflow('+',x,3.45e107);
  5863. // }
  5864. // int foo() {
  5865. // try {
  5866. // // ...
  5867. // f(1.2);
  5868. // // ...
  5869. // }
  5870. // catch(Overflow& oo) {
  5871. // // handle exceptions of type Overflow here
  5872. // }
  5873. // }
  5874. public void test15_1s1() throws Exception {
  5875. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5876. }
  5877. // int foo() {
  5878. // try {
  5879. // // ...
  5880. // }
  5881. // catch (...) { // catch all exceptions
  5882. // // respond (partially) to exception
  5883. // throw; //pass the exception to some
  5884. // // other handler
  5885. // }
  5886. // }
  5887. public void test15_1s6() throws Exception {
  5888. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5889. }
  5890. // class Matherr { virtual void vf(); };
  5891. // class Overflow: public Matherr { };
  5892. // class Underflow: public Matherr { };
  5893. // class Zerodivide: public Matherr { };
  5894. // void f()
  5895. // {
  5896. // try {
  5897. // }
  5898. // catch (Overflow oo) {
  5899. // // ...
  5900. // }
  5901. // catch (Matherr mm) {
  5902. // // ...
  5903. // }
  5904. // }
  5905. public void test15_3s4() throws Exception {
  5906. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5907. }
  5908. // void f() throw(int); // OK
  5909. // void (*fp)() throw (int); // OK
  5910. // void g(void pfa() throw(int)); // OK
  5911. public void test15_4s1a() throws Exception {
  5912. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5913. }
  5914. // typedef int (*pf)() throw(int); // illformed
  5915. public void test15_4s1b() throws Exception {
  5916. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5917. }
  5918. // struct B {
  5919. // virtual void f() throw (int, double);
  5920. // virtual void g();
  5921. // };
  5922. // struct D: B {
  5923. // void f(); // illformed
  5924. // void g() throw (int); // OK
  5925. // };
  5926. public void test15_4s3a() throws Exception {
  5927. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5928. }
  5929. // class A { };
  5930. // void (*pf1)(); // no exception specification
  5931. // void (*pf2)() throw(A);
  5932. // void f()
  5933. // {
  5934. // pf1 = pf2; // OK: pf1 is less restrictive
  5935. // pf2 = pf1; // error: pf2 is more restrictive
  5936. // }
  5937. public void test15_4s3b() throws Exception {
  5938. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5939. }
  5940. // class X { };
  5941. // class Y { };
  5942. // class Z: public X { };
  5943. // class W { };
  5944. // void f() throw (X, Y)
  5945. // {
  5946. // int n = 0;
  5947. // if (n) throw X(); // OK
  5948. // if (n) throw Z(); // also OK
  5949. // throw W(); // will call unexpected()
  5950. // }
  5951. public void test15_4s8() throws Exception {
  5952. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5953. }
  5954. // extern void f() throw(X, Y);
  5955. // void g() throw(X)
  5956. // {
  5957. // // f(); //OK
  5958. // }
  5959. public void test15_4s10() throws Exception {
  5960. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5961. }
  5962. // struct A {
  5963. // A();
  5964. // A(const A&) throw();
  5965. // ~A() throw(X);
  5966. // };
  5967. // struct B {
  5968. // B() throw();
  5969. // B(const B&) throw();
  5970. // ~B() throw(Y);
  5971. // };
  5972. // struct D : public A, public B {
  5973. // // Implicit declaration of D::D();
  5974. // // Implicit declaration of D::D(const D&) throw();
  5975. // // Implicit declaration of D::~D() throw (X,Y);
  5976. // };
  5977. public void test15_4s13() throws Exception {
  5978. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  5979. }
  5980. // #if VERSION == 1
  5981. // #define INCFILE "vers1.h"
  5982. // #elif VERSION == 2
  5983. // #define INCFILE "vers2.h" // and so on
  5984. // #else
  5985. // #define INCFILE "versN.h"
  5986. // #endif
  5987. public void test16_2s8() throws Exception {
  5988. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  5989. }
  5990. // // second pass of C++ spec is to get [Note: ]
  5991. // int f() {
  5992. // int a, b;
  5993. // /*...*/
  5994. // a = a + 32760 + b + 5;
  5995. // a = (((a + 32760) + b) + 5);
  5996. // a = ((a + b) + 32765);
  5997. // a = ((a + 32765) + b);
  5998. // a = (a + (b + 32765));
  5999. // }
  6000. public void test18_2_1_5s2() throws Exception {
  6001. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6002. }
  6003. // struct X {
  6004. // enum E { z = 16 };
  6005. // int b[X::z]; // OK
  6006. // };
  6007. public void test3_3_1s4() throws Exception {
  6008. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6009. }
  6010. // typedef int f;
  6011. // struct A {
  6012. // friend void f(A &);
  6013. // operator int();
  6014. // void g(A a) {
  6015. // f(a);
  6016. // }
  6017. // };
  6018. public void test3_4_1s3() throws Exception {
  6019. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6020. }
  6021. // struct A {
  6022. // int a;
  6023. // };
  6024. // struct B: virtual A { };
  6025. // struct C: B { };
  6026. // struct D: B { };
  6027. // struct E: public C, public D { };
  6028. // struct F: public A { };
  6029. // void f() {
  6030. // E e;
  6031. // e.B::a = 0; // OK, only one A::a in E
  6032. // F f;
  6033. // f.A::a = 1; // OK, A::a is a member of F
  6034. // }
  6035. public void test3_4_5s4() throws Exception {
  6036. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6037. }
  6038. // inline double fd() { return 1.0; }
  6039. // extern double d1;
  6040. // double d2 = d1; // unspecified:
  6041. // // may be statically initialized to 0.0 or
  6042. // // dynamically initialized to 1.0
  6043. // double d1 = fd(); // may be initialized statically to 1.0
  6044. public void test3_6_2s2() throws Exception {
  6045. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6046. }
  6047. // int main() {
  6048. // const char c = 'c';
  6049. // char* pc;
  6050. // const char** pcc = &pc; //1: not allowed
  6051. // *pcc = &c;
  6052. // *pc = 'C'; //2: modifies a const object
  6053. // }
  6054. public void test4_4s4() throws Exception {
  6055. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6056. }
  6057. // struct S {
  6058. // mutable int i;
  6059. // };
  6060. // int f() {
  6061. // const S cs;
  6062. // int S::* pm = &S::i; // pm refers to mutable member S::i
  6063. // cs.*pm = 88; // illformed: cs is a const object
  6064. // }
  6065. public void test5_5s5() throws Exception {
  6066. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6067. }
  6068. // namespace A {
  6069. // class X { };
  6070. // extern "C" int g();
  6071. // extern "C++" int h();
  6072. // }
  6073. // namespace B {
  6074. // void X(int);
  6075. // extern "C" int g();
  6076. // extern "C++" int h();
  6077. // }
  6078. // using namespace A;
  6079. // using namespace B;
  6080. // void f() {
  6081. // X(1); //error: name X found in two namespaces
  6082. // g(); //okay: name g refers to the same entity
  6083. // h(); //error: name h found in two namespaces
  6084. // }
  6085. public void test7_3_4s4() throws Exception {
  6086. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6087. }
  6088. // void print(int a, int)
  6089. // {
  6090. // //printf("a = %d",a);
  6091. // }
  6092. public void test8_4s5() throws Exception {
  6093. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6094. }
  6095. // int a;
  6096. // const int b = a;
  6097. // int c = b;
  6098. public void test8_5s14() throws Exception {
  6099. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6100. }
  6101. // struct B {
  6102. // virtual void f();
  6103. // };
  6104. // struct D : B {
  6105. // void f(int);
  6106. // };
  6107. // struct D2 : D {
  6108. // void f();
  6109. // };
  6110. public void test10_3s3() throws Exception {
  6111. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6112. }
  6113. // struct B {
  6114. // virtual ~B();
  6115. // void operator delete(void*, size_t);
  6116. // };
  6117. // struct D : B {
  6118. // void operator delete(void*);
  6119. // };
  6120. // void f()
  6121. // {
  6122. // B* bp = new D;
  6123. // delete bp; //1: uses D::operator delete(void*)
  6124. // }
  6125. public void test12_5s7a() throws Exception {
  6126. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6127. }
  6128. // struct B {
  6129. // virtual ~B();
  6130. // void operator delete[](void*, size_t);
  6131. // };
  6132. // struct D : B {
  6133. // void operator delete[](void*, size_t);
  6134. // };
  6135. // void f(int i)
  6136. // {
  6137. // D* dp = new D[i];
  6138. // delete [] dp; // uses D::operator delete[](void*, size_t)
  6139. // B* bp = new D[i];
  6140. // delete[] bp; // undefined behavior
  6141. // }
  6142. public void test12_5s7b() throws Exception {
  6143. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6144. }
  6145. // struct A { };
  6146. // void operator + (A, A);
  6147. // struct B {
  6148. // void operator + (B);
  6149. // void f ();
  6150. // };
  6151. // A a;
  6152. // void B::f() {
  6153. // //operator+ (a,a); // ERROR - global operator hidden by member
  6154. // a + a; // OK - calls global operator+
  6155. // }
  6156. public void test13_3_1_2s10() throws Exception {
  6157. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6158. }
  6159. // template<class T> class myarray { };
  6160. // template<class K, class V, template<class T> class C = myarray>
  6161. // class Map {
  6162. // C<K> key;
  6163. // C<V> value;
  6164. // // ...
  6165. // };
  6166. public void test14_1s2() throws Exception {
  6167. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6168. }
  6169. // class T { };
  6170. // int i;
  6171. // template<class T, T i> void f(T t)
  6172. // {
  6173. // T t1 = i; // templateparameters T and i
  6174. // ::T t2 = ::i; // global namespace members T and i
  6175. // }
  6176. public void test14_1s3() throws Exception {
  6177. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6178. }
  6179. // template<int* p> class X { };
  6180. // int a[10];
  6181. // struct S { int m; static int s; } s;
  6182. // X<&a[2]> x3; // error: address of array element
  6183. // X<&s.m> x4; // error: address of nonstatic member
  6184. // X<&s.s> x5; // error: &S::s must be used
  6185. // X<&S::s> x6; // OK: address of static member
  6186. public void test14_3_2s3() throws Exception {
  6187. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6188. }
  6189. // template<class T, char* p> class X {
  6190. // // ...
  6191. // X();
  6192. // X(const char* q) { }
  6193. // };
  6194. // X<int,"Studebaker"> x1; // error: string literal as template argument
  6195. // char p[] = "Vivisectionist";
  6196. // X<int,p> x2; // OK
  6197. public void test14_3_2s2() throws Exception {
  6198. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6199. }
  6200. // template<const int& CRI> struct B { /* ... */ };
  6201. // B<1> b2; // error: temporary would be required for template argument
  6202. // int c = 1;
  6203. // B<c> b1; // OK
  6204. public void test14_3_2s4() throws Exception {
  6205. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6206. }
  6207. // template<const int* pci> struct X { };
  6208. // int ai[10];
  6209. // X<ai> xi; // array to pointer and qualification conversions
  6210. // struct Y { };
  6211. // template<const Y& b> struct Z { };
  6212. // Y y;
  6213. // Z<y> z; // no conversion, but note extra cvqualification
  6214. // template<int (&pa)[5]> struct W { };
  6215. // int b[5];
  6216. // W<b> w; // no conversion
  6217. // void f(char);
  6218. // void f(int);
  6219. // template<void (*pf)(int)> struct A { };
  6220. // A<&f> a; // selects f(int)
  6221. public void test14_3_2s5() throws Exception {
  6222. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6223. }
  6224. // template <class T> struct A {
  6225. // void f(int);
  6226. // template <class T2> void f(T2);
  6227. // };
  6228. // template <> void A<int>::f(int) { } // nontemplate member
  6229. // template <> template <> void A<int>::f<>(int) { } // template member
  6230. // int main()
  6231. // {
  6232. // A<char> ac;
  6233. // ac.f(1); //nontemplate
  6234. // ac.f('c'); //template
  6235. // ac.f<>(1); //template
  6236. // }
  6237. public void test14_5_2s2() throws Exception {
  6238. parse(getAboveComment(), ParserLanguage.CPP, true, 0); //should be 0
  6239. }
  6240. // template<class T1, class T2, int I> class A<T1, T2, I> { }; // error
  6241. public void test14_5_5s5() throws Exception {
  6242. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6243. }
  6244. // template<class T> struct A {
  6245. // class C {
  6246. // template<class T2> struct B { };
  6247. // };
  6248. // };
  6249. // // partial specialization of A<T>::C::B<T2>
  6250. // template<class T> template<class T2>
  6251. // struct A<T>::C::B<T2*> { };
  6252. // A<short>::C::B<int*> absip; // uses partial specialization
  6253. public void test14_5_5s6() throws Exception {
  6254. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6255. }
  6256. // namespace N {
  6257. // template<class T1, class T2> class A { }; // primary template
  6258. // }
  6259. // using N::A; // refers to the primary template
  6260. // namespace N {
  6261. // template<class T> class A<T, T*> { }; // partial specialization
  6262. // }
  6263. // A<int,int*> a; // uses the partial specialization, which is found through
  6264. // // the using declaration which refers to the primary template
  6265. public void test14_5_5s7() throws Exception {
  6266. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6267. }
  6268. // template<class T> void f();
  6269. // template<int I> void f(); // OK: overloads the first template
  6270. // // distinguishable with an explicit template argument list
  6271. public void test14_5_6_1s4() throws Exception {
  6272. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6273. }
  6274. // template <int I> class A;
  6275. // template <int I, int J> A<I+J> f/*1*/(A<I>, A<J>); // #1
  6276. // template <int K, int L> A<K+L> f/*2*/(A<K>, A<L>); // same as #1
  6277. // template <int I, int J> A<I-J> f/*3*/(A<I>, A<J>); // different from #1
  6278. public void test14_5_6_1s5() throws Exception {
  6279. final String content= getAboveComment();
  6280. IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
  6281. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  6282. ICPPFunctionTemplate f1= bh.assertNonProblem("f/*1*/", 1);
  6283. ICPPFunctionTemplate f2= bh.assertNonProblem("f/*2*/", 1);
  6284. ICPPFunctionTemplate f3= bh.assertNonProblem("f/*3*/", 1);
  6285. assertSame(f1, f2);
  6286. assertNotSame(f1, f3);
  6287. }
  6288. // template <int I> class A;
  6289. // template <int I, int J> void f/*1*/(A<I+J>); // #1
  6290. // template <int K, int L> void f/*2*/(A<K+L>); // same as #1
  6291. public void test14_5_6_1s6() throws Exception {
  6292. final String content= getAboveComment();
  6293. IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
  6294. BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
  6295. ICPPFunctionTemplate f1= bh.assertNonProblem("f/*1*/", 1);
  6296. ICPPFunctionTemplate f2= bh.assertNonProblem("f/*2*/", 1);
  6297. assertSame(f1, f2);
  6298. }
  6299. // template <class T> int f(T); // #1
  6300. // int f(int); // #2
  6301. // int k = f(1); // uses #2
  6302. // int l = f<>(1); // uses #1
  6303. public void test14_8_1s2b() throws Exception {
  6304. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6305. }
  6306. // #define TABSIZE 100
  6307. // int table[TABSIZE];
  6308. public void test15_3_5s3() throws Exception {
  6309. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6310. }
  6311. // int g(int);
  6312. // void f()
  6313. // {
  6314. // int i;
  6315. // int& r = i; // r refers to i
  6316. // r = 1; // the value of i becomes 1
  6317. // int* p = &r; // p points to i
  6318. // int& rr = r; // rr refers to what r refers to, that is, to i
  6319. // int (&rg)(int) = g; // rg refers to the function g
  6320. // rg(i); //calls function g
  6321. // int a[3];
  6322. // int (&ra)[3] = a; // ra refers to the array a
  6323. // ra[1] = i; // modifies a[1]
  6324. // }
  6325. public void test8_5_3s1() throws Exception { // TODO raised bug 90648
  6326. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6327. }
  6328. // struct A { }; // implicitlydeclared A::operator=
  6329. // struct B : A {
  6330. // B& operator=(const B &);
  6331. // };
  6332. // B& B::operator=(const B& s) {
  6333. // this->A::operator=(s); // wellformed
  6334. // return *this;
  6335. // }
  6336. public void test12s1() throws Exception {
  6337. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6338. }
  6339. // struct A { };
  6340. // struct B : virtual A { };
  6341. // struct C : B { };
  6342. // struct D : virtual A { D(A*); };
  6343. // struct X { X(A*); };
  6344. // struct E : C, D, X {
  6345. // E() : D(this), // undefined: upcast from E* to A*
  6346. // // might use path E* -> D* -> A*
  6347. // // but D is not constructed
  6348. // // D((C*)this), // defined:
  6349. // // E* -> C* defined because E() has started
  6350. // // and C* -> A* defined because
  6351. // // C fully constructed
  6352. // X(this) //defined: upon construction of X,
  6353. // // C/B/D/A sublattice is fully constructed
  6354. // { }
  6355. // };
  6356. public void test12_7s2() throws Exception {
  6357. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6358. }
  6359. // typedef int c;
  6360. // enum { i = 1 };
  6361. // class X {
  6362. // int i=3;
  6363. // char v[i];
  6364. // int f() { return sizeof(c); } // OK: X::c
  6365. // char c;
  6366. // enum { i = 2 };
  6367. // };
  6368. // typedef char* T;
  6369. // struct Y {
  6370. // typedef long T;
  6371. // T b;
  6372. // };
  6373. // typedef int I;
  6374. // class D {
  6375. // typedef I I; // error, even though no reordering involved
  6376. // };
  6377. public void test3_3_6s5() throws Exception { // 90606
  6378. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6379. }
  6380. // int f(double);
  6381. // int f(int);
  6382. // int (*pfd)(double) = &f; // selects f(double)
  6383. // int (*pfi)(int) = &f; // selects f(int)
  6384. // int (*pfe)(...) = &f; // error: type mismatch
  6385. // int (&rfi)(int) = f; // selects f(int)
  6386. // int (&rfd)(double) = f; // selects f(double)
  6387. // void g() {
  6388. // (int (*)(int))&f; // cast expression as selector
  6389. // }
  6390. public void test13_4s5a() throws Exception { // bug 90674
  6391. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6392. }
  6393. // class A {
  6394. // public:
  6395. // int z;
  6396. // int z1;
  6397. // };
  6398. // class B : public A {
  6399. // int a;
  6400. // public:
  6401. // int b, c;
  6402. // int bf();
  6403. // protected:
  6404. // int x;
  6405. // int y;
  6406. // };
  6407. // class D : private B {
  6408. // int d;
  6409. // public:
  6410. // B::c; //adjust access to B::c
  6411. // B::z; //adjust access to A::z
  6412. // A::z1; //adjust access to A::z1
  6413. // int e;
  6414. // int df();
  6415. // protected:
  6416. // B::x; //adjust access to B::x
  6417. // int g;
  6418. // };
  6419. // class X : public D {
  6420. // int xf();
  6421. // };
  6422. // int ef(D&);
  6423. // int ff(X&);
  6424. public void test11_3s2() throws Exception { //bug 92793
  6425. IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6426. IASTCompositeTypeSpecifier D= getCompositeType(tu, 2);
  6427. IASTDeclaration accessDecl= getDeclaration(D, 2);
  6428. assertInstance(accessDecl, ICPPASTUsingDeclaration.class);
  6429. }
  6430. // int z() {
  6431. // int f(int);
  6432. // int a = 2;
  6433. // int b = f(a);
  6434. // int c(b);
  6435. // }
  6436. public void test8_5s2() throws Exception { // 90641
  6437. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6438. }
  6439. // // #include <cstddef>
  6440. // char *p;
  6441. // void *operator new(size_t, int);
  6442. // void foo() {
  6443. // const int x = 63;
  6444. // new (int(*p)) int; // newplacement expression
  6445. // new (int(*[x])); // new typeid
  6446. // }
  6447. public void test8_2s3() throws Exception {
  6448. parse(getAboveComment(), ParserLanguage.CPP, false, 0);
  6449. }
  6450. // template<class T> void f();
  6451. // template<int I> void f();
  6452. // void g()
  6453. // {
  6454. // f<int()>(); // int() is a typeid:call the first f()
  6455. // }
  6456. public void test14_3s2() throws Exception {
  6457. parse(getAboveComment(), ParserLanguage.CPP, true, 0);
  6458. }
  6459. }