https://github.com/aalmkainzi updated https://github.com/llvm/llvm-project/pull/226784
>From 7c81e84a437e3219045e04acd6643fb080fd7dab Mon Sep 17 00:00:00 2001 From: aalmkainzi <[email protected]> Date: Sun, 27 Sep 2026 13:38:10 +0300 Subject: [PATCH 1/3] only error out if __auto_type --- clang/lib/Sema/SemaTemplateDeduction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 653240092e64a..5a08eb3196b90 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5505,7 +5505,8 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result, DeducedFromInitRange = Init->getSourceRange(); } } else { - if (!getLangOpts().CPlusPlus && Init->refersToBitField()) { + if (!getLangOpts().CPlusPlus && Init->refersToBitField() && + AT->getKeyword() == AutoTypeKeyword::GNUAutoType) { Diag(Loc, diag::err_auto_bitfield); return TemplateDeductionResult::AlreadyDiagnosed; } >From 767dadc57fddb0b98705630e812484bfcd934c98 Mon Sep 17 00:00:00 2001 From: aalmkainzi <[email protected]> Date: Sun, 27 Sep 2026 16:14:47 +0300 Subject: [PATCH 2/3] added a test verifying that a bit-field is converted to its underlying type when type inference --- clang/test/Sema/c23-auto-bitfield.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 clang/test/Sema/c23-auto-bitfield.c diff --git a/clang/test/Sema/c23-auto-bitfield.c b/clang/test/Sema/c23-auto-bitfield.c new file mode 100644 index 0000000000000..0c93897f1ee61 --- /dev/null +++ b/clang/test/Sema/c23-auto-bitfield.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s +// expected-no-diagnostics + +void f() +{ + struct S { unsigned i : 1; }; + struct S s; + auto si = s.i; + static_assert(_Generic(si, unsigned int : 1, default : 0), "the underlying type of the bit-field is 'unsigned int'"); +} >From f8b9440070d7695b9a36ace8137bdef2c7e51b0e Mon Sep 17 00:00:00 2001 From: aalmkainzi <[email protected]> Date: Sun, 27 Sep 2026 16:41:18 +0300 Subject: [PATCH 3/3] added expected error in test --- clang/test/Sema/c23-auto-bitfield.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/test/Sema/c23-auto-bitfield.c b/clang/test/Sema/c23-auto-bitfield.c index 0c93897f1ee61..a11bccc6487f5 100644 --- a/clang/test/Sema/c23-auto-bitfield.c +++ b/clang/test/Sema/c23-auto-bitfield.c @@ -1,10 +1,12 @@ // RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s -// expected-no-diagnostics void f() { struct S { unsigned i : 1; }; struct S s; auto si = s.i; - static_assert(_Generic(si, unsigned int : 1, default : 0), "the underlying type of the bit-field is 'unsigned int'"); + static_assert(_Generic(si, unsigned int : 1, default : 0), + "the underlying type of the bit-field is 'unsigned int'"); + + __auto_type si2 = s.i; // expected-error {{cannot pass bit-field as __auto_type initializer in C}} } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
