I am experimenting with clang-tidy (while using a gcc) with all of it's checks. I was curious if the below case is a bug of clang-tidy as it contradicts my compiler's warnings. Here is a minimum example:
struct a{
virtual void func()=0;
virtual void func2()=0;
};
struct b:a{
void func() override {};
void func2() override {};
private:
int x{};
}
int main(){
b b_item;
}
The suggestion :
/home/main.cpp:7:8: note: use "__attribute__((aligned(0)))" to align struct 'a' to 0 bytes
struct a{
^
/home/main.cpp:13:8: warning: accessing fields in struct 'b' is inefficient due to padding; only needs 4 bytes but is using 16 bytes [altera-struct-pack-align]
struct b:a{
^
I will not demonstrate the code after the suggestion as clang-tidy made a lot of changes the important bit is:
struct a{
virtual void func()=0;
virtual void func2()=0;
} __attribute__((aligned(0)));
warning after calling fix:
warning: requested alignment ‘0’ is not a positive power of 2 [-Wattributes]
12 | } __attribute__((aligned(0)));