GCC 可以像 VS 一样产生结构/类名称不匹配吗?

发布于 2024-11-02 08:21:24 字数 468 浏览 0 评论 0原文

我想让 GCC 生成一个警告,当 VisualStudio 发现已使用 classstruct 声明的名称时,它会生成一条警告。 (警告 4099)这通常是由前向声明导致的,例如:

struct Base;
...
class Base { ... };

在这种情况下 VS 实际上无法链接,因此我已将警告升级为错误。由于这个项目是跨平台的,我希望在使用 GCC 编译时也发现这个问题——否则我可能会意外签入在 VS 中无法工作的代码。

是否有任何开关或方法可以让 GCC 也拒绝或警告此类类/结构声明不匹配?

注意:从评论中无法确定此警告是否合法。对于我的问题,它不相关,因为该条件导致 VisualStudio 中的链接失败(我不能忽略警告)。因此,我只想使用 GCC 来识别问题,这样我的 Windows 编译就不会突然停止工作。

I would like to get GCC to produce a warning that VisualStudio produces when it finds a name that has been declared with both class and struct. (Warning 4099) This usually results from forward declarations such as:

struct Base;
...
class Base { ... };

VS actually fails to link in this case so I've promoted the warning to an error. Since this project is cross-platform I would like to also discover this issue when compiling with GCC -- otherwise I can accidentally check in code that won't work in VS.

Is there any switch, or method, to get GCC to also reject, or warn, about such class/struct declaration mismatches?

NOTE: From the comments it is uncertain whether this warning is legitimate. For my question it isn't relevant since the condition causes the linking in VisualStudio to fail (I can't just ignore the warning). Thus I'd just like to identify the problems using GCC so my windows compiles don't suddenly stop working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与他有关 2024-11-09 08:21:24

从版本 10 开始,gcc 也像 clang 一样提供 -Wmismatched-tags 标志 https://stackoverflow.com /a/66640473/2436175

Since version 10 also gcc, like clang, offers the -Wmismatched-tags flag https://stackoverflow.com/a/66640473/2436175

暖伴 2024-11-09 08:21:24

gcc 不关心差异。 Itanium ABI 以相同的方式修饰 classstruct,使它们成为纯粹的语法差异。

Clang 有 -Wmismatched-tags 来激活此检测,但我找不到 gcc 等效项(如果有)。

gcc does not care about the difference. The Itanium ABI mangles class and struct the same way, leaving them as pure syntactic difference.

Clang has -Wmismatched-tags to activate this detection, but I could not find the gcc equivalent (if any).

往日情怀 2024-11-09 08:21:24

你用的是什么版本的VC++。 VC++ 6.0 中存在一个错误,这意味着它以不同的方式处理 structclass,但这在以后的编译器中已得到修复;例如,对于 VC++ 2005,我没有收到任何警告。

What version of VC++ are you using. There was an error in VC++ 6.0 which meant that it treated struct and class differently, but that's been fixed in later compilers; I don't get any warning with VC++ 2005, for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文