开发者

Can GCC produce struct/class name mismatches like VS?

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.


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


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜