Skip to content

Commit

Permalink
Extend test/Prompt/decls.C to test ctor, dtor and operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyilism authored and jenkins committed Jul 18, 2023
1 parent 884b73b commit b9e8886
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/Prompt/decls.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// RUN: cat %s | %cling -I%p | FileCheck %s
#include <cmath>
#include <iostream>

struct S{int i;} ss;
S s = {12 };
Expand All @@ -16,6 +17,44 @@ struct U{void f() const {};} uu;

struct V{V(): v(12) {}; int v; } vv;

struct typeA {
typeA(int i): num{i} {};
typeA();
~typeA();

typeA& operator()(int k);
const typeA& operator[](int k) const;

operator int() const;

int num;
};

typeA::typeA() = default;
::typeA::~typeA() {};
::typeA& ::typeA::operator()(int k) { return *this; }
const typeA& typeA::operator[](int k) const { return *this; }
bool operator>=(const typeA &lhs, int t) { return lhs.num >= t; }
bool operator<=(::typeA const &lhs, int t) { return lhs.num <= t; }
bool operator<(typeA const&lhs, int t) { return lhs.num < t; }
bool operator>(const typeA &lhs, int t) { return lhs.num > t; }
::typeA operator+(const typeA &lhs, const ::typeA &rhs) {
return typeA{lhs.num + rhs.num};
}
::typeA operator "" _tA(unsigned long long int t) { return typeA{static_cast<int>(t)}; }
std::ostream& operator<<(std::ostream& os, const typeA& a) {return (os << a.num);}
typeA::operator int() const { return num + 7; }

std::cout << 76601_tA; // CHECK:76601
6551_tA(99)[4].num // CHECK:6551
typeA{-675} > 0 // CHECK:false
99_tA >= 99 // CHECK:true
::typeA(31) < 31 // CHECK:false
(60_tA + 3_tA).num // CHECK:63
static_cast<int>(18_tA) // CHECK:25

::atoi("42") // CHECK:42

int i = 12;
float f = sin(12);
int j = i;
Expand Down

0 comments on commit b9e8886

Please sign in to comment.