[Bug c++/106141] New: Better wording for warning: ‘Child’ has a base ‘Base<(& hello)>’ whose type uses the anonymous namespace [-Wsubobject-linkage]
jlame646 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 30 04:03:11 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106141
Bug ID: 106141
Summary: Better wording for warning: ‘Child’ has a base
‘Base<(& hello)>’ whose type uses the anonymous
namespace [-Wsubobject-linkage]
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
The following program which has undefined behavior NDR produces a warning that
can be worded in a better way:
To reproduce the warning refer to the following:
https://wandbox.org/permlink/M7O7mJS1KJpPuJ05
----base.hh----
#pragma once
#include <iostream>
template<char const *s>
class Base
{
public:
void print()
{
std::cout << s << std::endl;
}
};
----child.hh----
#pragma once
#include "base.hh"
constexpr char const hello[] = "Hello world!";
class Child : public Base<hello>
{
};
----main.cpp----
#include "child.hh"
int main(void)
{
Child c;
c.print();
return 0;
}
The warning produced from the above program will be:
In file included from main.cpp:1:
child.hh:7:7: warning: ‘Child’ has a base ‘Base<(& hello)>’ whose type uses the
anonymous namespace [-Wsubobject-linkage]
7 | class Child : public Base<hello>
| ^~~~~
------------------------------------------------------------
This warning should instead say:
child.hh:7:7: warning: ‘Child’ has a base ‘Base<(& hello)>’ whose type refers
to an entity with internal linkage [-Wsubobject-linkage]
-------------------------------------------------------------
Note in the above modified/suggested warning we have changed "whose type uses
the anonymous namespace" to "whose type refers to an entity with internal
linkage"
The reproducible example can be found here:
https://wandbox.org/permlink/M7O7mJS1KJpPuJ05
More information about the Gcc-bugs
mailing list