https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86491
Bug ID: 86491
Summary: bogus and unsuppressible warning: 'YYY' has a base
'ZZZ' whose type uses the anonymous namespace
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jason.vas.dias at gmail dot com
Target Milestone: ---
Created attachment 44383
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44383&action=edit
test code demonstrating problem as described above.
This could be a duplicate of (now closed) bug #57317 ,
or a demonstration that the fix for that bug is not complete.
It occurs with all versions of GCC on Linux x86_64 - tested:
o RHEL7 system compiler: 4.8.5 (rpm: 4.8.5-28.el7_5.1.x86_64)
My own builds of:
o gcc 5.4.0
o gcc 6.4.1 (from gcc-6-branch r260630)
o gcc 7.3.1 (r260631)
o gcc 8.1.0 (r261026)
.
The following test code triggers a -Wsubobject-linkage warning,
with all the above compilers :
./t2.H:14:9: warning: 'N::D' has a base 'N::NT<N::NA::C, (& N::NA::c_),\
&N::NA::C::m> whose type uses the anonymous namespace \
[enabled by default]
class D : public NT<NA::C,&NA::c_,&NA::C::m>
^
I have constructed the following test code,
which triggers the same -Wsubobject-linkage warning
I am seeing in a large more complex real-world example.
I am not intentionally using the anonymous namespace
in any of this code, and I cannot for the life of me
see how any part of it uses the anonymous namespace:
Test Code :
File t1.H:
<quote><code><pre>
// t1.H :
namespace N
{
template < class _C_, _C_ *_C_OBJ_, void (_C_::*_M_)() >
class NT
{ static constexpr _C_ *c_ = _C_OBJ_;
public:
NT()
{ (c_->*_M_)();
}
};
}
</pre></code></quote>
File t2.H:
<quote><code><pre>
// t2.H :
#include <t1.H>
namespace N
{
namespace NA
{
class C
{ public:
void m()
{}
};
static C c_;
}
class D : public NT<NA::C,&NA::c_,&NA::C::m>
{public:
typedef NT<NA::C,&NA::c_,&NA::C::m> NT_t;
D(): NT_t()
{}
};
}
file tM.C (main program):
</pre></code></quote>
#include <t2.H>
extern int main()
{ N::D d;
(void)d;
return 0;
}
<quote><code><pre>
The above files are included in the attached
'Wsubobject-linkage-anon-base-bug.tar' file, which includes a make file:
$ tar -xpf Wsubobject-linkage-anon-base-bug.tar
$ cd Wsubobject-linkage-anon-base-bug
$ make
g++ -std=gnu++14 -I. -Wall -Wextra -Werror -o tM tM.C
In file included from tM.C:1:0:
./t2.H:14:9: error: 'N::D' has a base 'N::NT<N::NA::C, (& N::NA::c_),
&N::NA::C::m>' whose type uses the anonymous namespace [-Werror]
class D : public NT<NA::C,&NA::c_,&NA::C::m>
^
cc1plus: all warnings being treated as errors
make: *** [Makefile:4: tM] Error 1