S. *_*zor 8 c++ inheritance gcc templates strict-aliasing
以下代码在gcc中向我发出警告,我违反了严格的别名规则:
struct Base {
int field = 2;
};
template <typename T>
struct Specialization: public Base {
void method() {
Specialization copy;
field = copy.field;
}
};
int main() {
Specialization<int> s;
s.method();
}
Run Code Online (Sandbox Code Playgroud)
警告:解除引用类型惩罚指针将>破坏严格别名规则[-Wstrict-aliasing] field = copy.field;
当我删除模板时,似乎编译得很好.
struct Base {
int field = 2;
};
struct Specialization: public Base {
void method() {
Specialization copy;
field = copy.field;
}
};
int main(){
Specialization s;
s.method();
}
Run Code Online (Sandbox Code Playgroud)
我真的打破严格的别名规则还是GCC产生假阳性?
我-Wstrict-aliasing=3 -O3在GCC8上使用
不,所提供的代码中不存在严格的别名规则违规。它看起来像是 gcc 中的一个错误。
您可以向 gcc 提交错误报告(我无法找到与所提供的代码片段相关的任何内容),但是,根据https://gcc.gnu.org/bugzilla/show_bug.cgi?id=的生命周期和时间来判断41874我不希望立即修复。
| 归档时间: |
|
| 查看次数: |
165 次 |
| 最近记录: |