[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 28 10:45:36 PDT 2023


shafik added a comment.

In D153857#4455480 <https://reviews.llvm.org/D153857#4455480>, @Fznamznon wrote:

>> MSVC rejects the first but accepts the second which I think is wrong but worth testing:
>>
>> alignof(struct B {});
>> sizeof(struct B{});
>
> These don't have `new` so they are not affected by the patch ATM.
> But why MSVC wrong? Operand of `alignof` is a `type-id` which is not `defining-type-id` meaning it shouldn't be parsed as type definition. So, `struct B{}` there is a reference to `struct B` with braced initializer, i.e. object creation. That is not a `type-id`, right? On the opposite, `sizeof` can accept either `type-id` or an expression, I guess this is why MSVC accepts.

new is special b/c it is has `new-initializer` after the `type-id` so that can be an initialization: https://eel.is/c++draft/expr.new#nt:new-expression in `sizeof` it is a definition which is not allowed and so it should be rejected.

if you do:

  struct B{ int x; };
  
  void f() {
     struct B{};
  }

That is a definition in `f`: https://godbolt.org/z/38eM6z17K


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153857



More information about the cfe-commits mailing list