This repository was archived by the owner on Aug 29, 2023. It is now read-only.
forked from facebookarchive/flint
-
Notifications
You must be signed in to change notification settings - Fork 20
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
False non-virtual dtor warning when passing structs or using nested classes #62
Copy link
Copy link
Open
Description
The following four test cases all cause Flint++ to generate the warning "Classes with virtual functions should not have a public non-virtual destructor" erroneously, I believe. In three of the cases a struct is being returned from or passed to a method. In the last one there is a class inside another class. Strangely the warnings go away if the line following the one causing the warning is deleted or commented out.
To reproduce, run flint++ in the same directory as the following four header files
$ ~/cpp/flint++_false_vdtors$ flint++ -l3
[Warning] cev.h:12: Classes with virtual functions should not have a public non-virtual destructor.
[Warning] no_ctor.h:12: Classes with virtual functions should not have a public non-virtual destructor.
[Warning] no_ctor.h:15: Classes with virtual functions should not have a public non-virtual destructor.
[Warning] pd.h:9: Classes with virtual functions should not have a public non-virtual destructor.
[Warning] struct_return.h:12: Classes with virtual functions should not have a public non-virtual destructor.
Lint Summary: 4 files
Errors: 0 Warnings: 5 Advice: 0
Estimated Lines of Code: 72
Instead, I would expect no warnings.
CentOS Linux release 7.6.1810 (Core)
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
#ifndef CEV_H
#define CEV_H
#include <time.h>
class A
{
public:
A() {}
virtual ~A() {}
virtual struct timeval getLastUpdate() { timeval t; return t; } // [Warning] cev.h:12: Classes with virtual functions should not have a public non-virtual destructor.
virtual void m() {} // Deleting or commenting out this line gets rid of the warning in the line above
};
#endif /* CEV_H */
#ifndef FOO_H
#define FOO_H
#include <sys/time.h>
struct Z { int i, j; };
class Foo
{
public:
virtual ~Foo() {}
virtual void bar(struct timeval timestamp) {} // [Warning] no_ctor.h:12: Classes with virtual functions should not have a public non-virtual destructor.
virtual void bar(Z z) {} // No warning
virtual void bar(struct Z& z) {} // [Warning] no_ctor.h:15: Classes with virtual functions should not have a public non-virtual destructor.
virtual void baz() {} // Removing this line gets rid of the warning for the line above
};
#endif /* FOO_H */
#ifndef STRUCT_RETURN_H
#define STRUCT_RETURN_H
#include <time.h>
class C
{
public:
C() {}
virtual ~C() {}
virtual struct timeval getLastUpdate() { return {0,0}; } // [Warning] struct_return.h:12: Classes with virtual functions should not have a public non-virtual destructor.
virtual bool foo(); // Deleting or commenting this line gets rid of the warning in the line above
};
#endif /* STRUCT_RETURN_H */
#ifndef PD_H
#define PD_H
class B
{
public:
virtual ~B();
class C // [Warning] pd.h:9: Classes with virtual functions should not have a public non-virtual destructor.
{
public:
C() {}
};
virtual bool foo(); // Deleting or commenting this line gets rid of the warning in the line above
};
#endif /* PD_H */
Metadata
Metadata
Assignees
Labels
No labels