Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

c++ - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...