https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106051
Bug ID: 106051
Summary: -Wmismatched-tags gives false positive warning when
"class C" is "using namespace"d into a namespace with
another "class C" declaration
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: beardsley.matt.j at gmail dot com
Target Milestone: ---
https://godbolt.org/z/sx8aT3EKh
The following uses gcc built from a fresh repo that I just cloned earlier today
(default build settings)
tmp.cpp:
namespace ns {
class C {};
}
using namespace ns;
class C;
No ambiguity with the warning off:
$ g++ -c tmp.cpp -o /dev/null -Wno-mismatched-tags
(no output)
Now it's ambiguous (also refers to it as "struct C" but it's really "class C")
$ g++ -c tmp.cpp -o /dev/null -Wmismatched-tags
tmp.cpp:5:7: error: reference to ‘C’ is ambiguous
5 | class C;
| ^
tmp.cpp:2:7: note: candidates are: ‘class ns::C’
2 | class C {};
| ^
tmp.cpp:5:7: note: ‘struct C’
5 | class C;
| ^
Not sure how noteworthy this is but if the last 2 lines are swapped the warning
goes away:
tmp.cpp:
namespace ns {
class C {};
}
class C;
using namespace ns;
$ g++ -c tmp.cpp -o /dev/null -Wno-mismatched-tags
(no output)
$ g++ -c tmp.cpp -o /dev/null -Wmismatched-tags
(no output)