| Issue |
52843
|
| Summary |
[Clang Static Analyzer] Souldn't const member functions be assumend to not change object state?
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
kasper93
|
Hi,
Let's consider this simple example. When body of `size()` function is not visible to analyzer it does complain ` Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]` which is pretty valid diagnostic, but since `size()` is const, shouldn't we assume that object state didn't change between consecutive calls? Of course if we have function definition there is no problem.
Tested with ```Debian clang version 14.0.0-++20211221072551+c5cf7d910e54-1~exp1~20211221072652.95```
``` C++
struct
{
// int size() const { return size_; };
int size() const;
private:
int size_ = 0;
} bar_;
int foo()
{
int a;
if (bar_.size() > 1)
a = 0;
if (bar_.size() > 1)
return a;
return 0;
}
```
Thanks,
Kacper
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs