C++ Logo

std-proposals

Advanced search

Re: Are constrained type barred from std:: implementations?

From: Bo Persson <bo_at_[hidden]>
Date: Fri, 27 Aug 2021 16:19:25 +0200
On 2021-08-27 at 15:45, DBJ via Std-Proposals wrote:
> I am arguing that code should be not compiling. Not the opposite.
>
> https://godbolt.org/z/d13x5fr9G <https://godbolt.org/z/84TK41c3P>
>
> basic_char_traits<void***> is illegal of course. Repeat: I am arguing
> that code should be not compiling. But it does and there are no warnings
> whatsoever.

No, the string classes only require that the "char-like type" used is
"any non-array trivial standard-layout type".

http://eel.is/c++draft/strings.general

As it is, void*** satisfies that requirement. The way it could fail is
if the char_traits base class doesn't compile. The standard is a bit
unclear if it must, or if it is enough to have specializations for the
real character types.

http://eel.is/c++draft/char.traits#general-1

>
> The only two switches used are -pedantic and -Wall. So who do we blame:
> the compiler or the messenger (aka coder) or both?
>
> Or somebody explains that code compiling and being allowed is fine,
> because of some higher logic that escapes me... Why am I allowed
> to declare fake types from std:: templates?

They are not fake types just because the namespace name if "fake". You
are just creating an alias.

using container = std::vector<int>;

is probably used all over the place, in all kinds of application namespaces.



>
>
> On Fri, 27 Aug 2021 at 14:09, Edward Catmur via Std-Proposals
> <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>>
> wrote:
>
>
>
> On Fri, 27 Aug 2021 at 12:30, Giuseppe D'Angelo via Std-Proposals
> <std-proposals_at_[hidden]
> <mailto:std-proposals_at_[hidden]>> wrote:
>
> On 27/08/2021 13:09, DBJ via Std-Proposals wrote:
> > Thanks, Lenard, I just find it generally peculiar nobody in this
> > honorable forum seem genuinely perturbed
> >
> > This code <https://godbolt.org/z/84TK41c3P
> <https://godbolt.org/z/84TK41c3P>>
> >
> > is legal...? Perhaps there is something obvious escaping my
> cognitive
> > abilities...
>
> That code isn't legal, specifically
>
> #define typename(T_) (#T_)
>
> violates https://eel.is/c++draft/macro.names#2
> <https://eel.is/c++draft/macro.names#2> as typename is a keyword.
> https://eel.is/c++draft/tab:lex.key
> <https://eel.is/c++draft/tab:lex.key>
>
>
> Ignoring that (as the program seems to be unaffected by its
> removal), the program is ill-formed because
> basic_char_traits<void***> is not specialized (and cannot be
> specialized) and so does not meet the character traits requirements.
> http://eel.is/c++draft/string.view.template#general-1
> <http://eel.is/c++draft/string.view.template#general-1>
>

Received on 2021-08-27 09:19:39