Closed
Description
It seems that CBMC supports operator overloading according to Supported Language Features. However when I tried the following example:
//FILE: /home/hongce/sysClearn/sysCVerif/testop.cpp
#include <cassert>
class t1{
public:
t1 (int n) :value(n) {}
public:
int value;
int operator[](int n) { return n*value; }
};
int operator+(t1 left, int right) {return left.value+right;}
int main()
{
t1 t(10);
int t_1 = t + 5;
int t_2 = t[5];
assert(t_1 == 15);
assert(t_2 == 50);
return 0;
}
This is the error.
$ ~/cbmc-src/cbmc/src/cbmc/cbmc testop.cpp
CBMC version 5.7 64-bit x86_64 linux
Parsing testop.cpp
Converting
Type-checking testop
file testop.cpp line 18 function main: operator '+' not defined for types 'class' and 'int'
CONVERSION ERROR
Even after changing addition overloading as the member of class t1, it does not work.
Mysteriously the index operator works, if I remove the addition overloading staffs.
Does anyone know what is the problem?