Skip to content

const fields in constructors

ID0002395: This issue was created automatically from Mantis Issue 2395. Further discussion may take place here.


Id Project Category View Due Date Updated
ID0002395 Frama-C Plug-in > clang public 2018-08-24 2018-09-07
Reporter abhishek.anand.iitg@gmail.com Assigned To virgile Resolution open
Priority normal Severity minor Reproducibility always
Platform - OS Manjaro OS Version 8/23/2018
Product Version Frama-C 17-Chlorine Target Version - Fixed in Version -

Description :

Const fields in constructors are not handled properly.

Below is an example:

class A { public: const int x; A(int y): x(y){} };

int main() { A a(0); }

I get the following error: root@27db7a69b96a:/hostshare# frama-c -print constFieldBug.cpp [kernel] Parsing constFieldBug.cpp (external front-end) Now output intermediate result [kernel] constFieldBug.cpp:4: User Error: Cannot assign to non-modifiable lval this->x [kernel] User Error: stopping on file "constFieldBug.cpp" that has errors. [kernel] Frama-C aborted: invalid user input.

Perhaps such constructors have to first initialize all fields using the {} notation and then do the rest of the construction of all fields and then do the rest of the constructor body.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information