C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Equivalence of unnamed types across translation units
From: Brian Bi (bbi5291_at_[hidden])
Date: 2019-07-30 10:48:26


In C++20 the wording was changed so that only names have linkage. I assume
the types are different because there's no rule saying they're the same, so
I would agree that multiple definitions of `b` violate the ODR.

In the second and third cases, I think this is less controversial.

On Mon, Jul 29, 2019 at 10:46 PM Myria via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> Let's say that you had a header file #included by multiple translation
> units that contains:
>
> const struct { } a;
> struct b : decltype(a) { };
>
> Is this a violation of the One Definition Rule? The unnamed type of
> "a" has either no or internal linkage (I'm not sure which), so each
> translation unit's struct b derives from a different base class,
> breaking the One Definition Rule...?
>
> Similarly, this could be asked about anonymous namespaces and lambdas:
>
> namespace { struct a { }; }
> struct b : a { };
>
> static auto a = []{};
> struct b : decltype(a) { };
>
> Melissa
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

-- 
*Brian Bi*


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups