[Bug c++/86254] New: g++ rejects legal code?
zhonghao at pku dot org.cn
gcc-bugzilla@gcc.gnu.org
Thu Jun 21 02:04:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86254
Bug ID: 86254
Summary: g++ rejects legal code?
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: zhonghao at pku dot org.cn
Target Milestone: ---
The code is as follow:
namespace N {
extern "C" {
extern const int foobar;
const int foobar = 1;
struct S { static const int foobar; };
const int S::foobar = 2;
}
}
int main () { return !(N::foobar + 1 == N::S::foobar); }
clang++ accepts the code, but g++ produces error messages:
conflicting declaration of ‘const int N::S::foobar’ with ‘C’ linkage
const int S::foobar = 2;
previous declaration with ‘C++’ linkage
struct S { static const int foobar; };
Indeed, the code comes from a bug report of gcc
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33786). A previous version of g++
produces a different error message, but was fixed in the latest version.
I reported this as a bug in clang: https://bugs.llvm.org/show_bug.cgi?id=37844
However, Richard Smith told me that gcc is wrong. He cited a sentence "A C
language linkage is ignored in determining the language linkage of the names of
class members" to support his statement. This sounds like a specification. So,
is this really a bug in gcc?
More information about the Gcc-bugs
mailing list