Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc mismatched-tags option giving `unrecognized command line option`

I was trying to activate the option -Wmismatched-tags on gcc (detect inconsistent class/struct declaration, which might happens when using forward declaration), but on Ubuntu I get

c++: error: unrecognized command line option '-Wmismatched-tags'

My gcc version:

# gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.

Looking here it seems like it was integrated in gcc 4.9.0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339

Am I doing something wrong, or is the option actually not available anymore?

I am aware of Can GCC produce struct/class name mismatches like VS?, however the answer is 10 years old and I was hoping things had improved in the meantime.

Background: I need this in a project where we also build with clang, and where these inconsistencies are treated as error.

like image 499
Antonio Avatar asked Oct 25 '25 06:10

Antonio


1 Answers

Looking here it seems like it was integrated in gcc 4.9.0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339

Actually, it doesn't. It was reported in 2014 but as OP explained in #5th post:

I can't speak for MS, but the original warning I posted was produced by clang. It does seem to worry about mismatched tags.

In gcc -Wmismatched-tags was introduced only in December 2019 and became a part of GCC 10 release:

$ git describe e8f1ade269a39ea86a76a2440818e1512ed480ee
basepoints/gcc-10-5517-ge8f1ade269a

Luckily, these days we have docker and official GCC releases are officially distributed as docker images:

$ docker search gcc
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
gcc                                The GNU Compiler Collection is a compiling s…   587                 [OK]
(...)

so you can just do:

docker run --rm -it gcc

and either mount your source directory into the docker container or use TRAMP integration for docker containers or any other preferred tool to put your code into the container and use the newest gcc inside it:

root@53d309d5d619:/# g++ --version
g++ (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@53d309d5d619:/# g++  hello.cpp  -o hello -Wmismatched-tags
like image 50
Arkadiusz Drabczyk Avatar answered Oct 28 '25 02:10

Arkadiusz Drabczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!