[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 1 23:07:12 PDT 2022


rjmccall added a comment.

In D116203#3423594 <https://reviews.llvm.org/D116203#3423594>, @cjdb wrote:

> In D116203#3277515 <https://reviews.llvm.org/D116203#3277515>, @zoecarver wrote:
>
>> This patch looks awesome, Chris.
>>
>> Does it make sense to have builtins for `add_const`, etc.? Isn't `T const` already kind of a builtin for this?
>
> Potentially, but I need a core language lawyer to weigh in here. The library wording for `std::add_const<T>::type` is:
>
>> If `T` is a reference, function, or top-level `const`-qualified type, then type names the same type as `T`, otherwise `T const`.
>
> Although my understanding is that the `T const` in this case is redundant (and thus not applied per dcl.type.cv <https://eel.is/c++draft/dcl.type.cv#1>), the library wording goes out of its way to say "do nothing".

The language ignores attempts to add most qualifiers to function and reference types.  (The only exception is that we allow address space qualifiers on function types, but that's extension territory.)  Compilers will warn or error about it in various situations if you do it directly, but not if you do it via a template or a typedef.  This is [dcl.type.cv]p1 (redundant const), [dcl.fct]p7 (function types), and [dcl.ref]p1 (references).

I think the spec is just trying to say that this isn't an end-around the other language rules and it doesn't construct const-qualified versions of certain types that otherwise the language is at pains to never construct.



================
Comment at: clang/lib/Sema/SemaType.cpp:9227
 
-        DiagnoseUseOfDecl(ED, Loc);
+  QualType Underlying = Context.getIntTypeForBitwidth(
+      Context.getIntWidth(BaseType), IsMakeSigned);
----------------
cjdb wrote:
> erichkeane wrote:
> > Can you add a couple of tests to make sure this works with _BitInt?  Note that this + the libc++ fixes get this done: https://github.com/llvm/llvm-project/issues/50427
> Done for `_BitInt`. Is there a corresponding unsigned `_BitInt`? Neither `_BitUint`, `BitUInt`, nor `_UBitInt` work :(
I believe `_BitInt` works like `int` et al., so it'd be `unsigned _BitInt`, 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116203/new/

https://reviews.llvm.org/D116203



More information about the cfe-commits mailing list