Title
External linkage and nameless entities
Status
nad
Section
6.6 [basic.link]
Submitter
Daveed Vandevoorde

Created on 2000-04-12.00:00:00 last changed 45 months ago

Messages

Date: 2021-02-15.00:00:00

Rationale (February, 2021):

The resolution of issue 2300 and paper P2115R0 have resolved these questions.

Date: 2022-11-20.07:54:16

It is unclear to what extent entities without names match across translation units. For example,

    struct S {
       int :2;
       enum { a, b, c } x;
       static class {} *p;
    };

If this declaration appears in multiple translation units, are all these members "the same" in each declaration?

A similar question can be asked about non-member declarations:

    // Translation unit 1:
    extern enum { d, e, f } y;

    // Translation unit 2:
    extern enum { d, e, f } y;

    // Translation unit 3:
    enum { d, e, f } y;

Is this valid C++? Is it valid C?

James Kanze: S::p cannot be defined, because to do so requires a type specifier and the type cannot be named. ::y is valid C because C only requires compatible, not identical, types. In C++, it appears that there is a new type in each declaration, so it would not be valid. This differs from S::x because the unnamed type is part of a named type — but I don't know where or if the Standard says that.

John Max Skaller: It's not valid C++, because the type is a synthesised, unique name for the enumeration type which differs across translation units, as if:

    extern enum _synth1 { d,e,f} y;
    ..
    extern enum _synth2 { d,e,f} y;

had been written.

However, within a class, the ODR implies the types are the same:

    class X { enum { d } y; };

in two translation units ensures that the type of member y is the same: the two X's obey the ODR and so denote the same class, and it follows that there's only one member y and one type that it has.

(See also issues 132 and 216.)

History
Date User Action Args
2021-02-17 00:00:00adminsetmessages: + msg6503
2021-02-17 00:00:00adminsetstatus: open -> nad
2000-04-12 00:00:00admincreate