Fznamznon added a comment.

> What about
> template <typename T>
> struct A { };
>
>   void foo() {
>     new struct A<int> {};
>   }
>
> I think this should be allowed, right?

Yes, I think so. The patch helps to allow. Thanks, I'll add it to the test.

> 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.



================
Comment at: clang/include/clang/Parse/Parser.h:2359
     case DeclSpecContext::DSC_template_param:
+    case DeclSpecContext::DSC_new:
       return ImplicitTypenameContext::Yes;
----------------
shafik wrote:
> Should this be below since `DeclaratorContext::CXXNew` was grouped w/ 
> `DSC_normal` normal before?
Not really. Since there was no `DeclSpecContext` for `new` expression, it was 
mostly handled as if it was `DSC_type_specifier`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153857

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to