[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

Jerin Philip via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 16 23:59:39 PDT 2023


================
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s
+// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s
+
+_Alignas(int) struct c1; // expected-warning {{attribute '_Alignas' before "struct" is ignored}}
+alignas(int) struct c1; // expected-warning {{attribute 'alignas' before "struct" is ignored}}
----------------
jerinphilip wrote:

I tried to add a C23 test carrying over [D141177 (comment)](https://reviews.llvm.org/D141177#4606499_). The C23 test fails at the moment, because a CXX11 path is activated. My understanding is `alignas` being present pre C23 only in C++ has parse-paths that take the only C++ existence into consideration (from [isCXX11AttributeSpecifier](https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/lib/Parse/ParseTentative.cpp#L740)). 

It ends up at https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/include/clang/Parse/Parser.h#L2743 triggering the error messages to move it outward:
https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/lib/Parse/ParseDecl.cpp#L1791

Is it possible to decouple C23 from this what this PR addresses?

https://github.com/llvm/llvm-project/pull/65638


More information about the cfe-commits mailing list