Skip to content

Reject auto combined with type specifiers in C++ - #208552

Merged
to268 merged 13 commits into
llvm:mainfrom
osamakader:fix-auto-with-type
Jul 11, 2026
Merged

Reject auto combined with type specifiers in C++#208552
to268 merged 13 commits into
llvm:mainfrom
osamakader:fix-auto-with-type

Conversation

@osamakader

@osamakader osamakader commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Follow-up of #166004

  • Diagnose C++ declarations that combine auto with another type specifier, such as auto int .
  • Preserve C/C23 handling where auto can still be interpreted as a storage-class specifier in valid combinations.
  • Fix parser disambiguation so auto Use = 0 treats Use as the declarator name before type lookup, avoiding ambiguous lookup regressions.

osamakader added 12 commits July 9, 2026 21:10
This commit fixes several issues related to 'auto' type specifier handling.

Core implementation:
- Add ConflictingTypeSpecifier flag to DeclSpec to track when 'auto' conflicts
  with another type specifier (e.g., 'auto int' or 'int auto'). This allows
  Finish() to properly handle the conflict based on language mode rather than
  immediately emitting an error during parsing.

1. Fix 'auto auto' duplicate detection: Keep TypeSpecType as TST_auto after
   emitting error so subsequent checks can emit function-specific errors
   (e.g., 'not allowed in function prototype').

2. Fix OpenCL 'auto' and 'register' storage class errors: Reorder checks to
   prioritize OpenCL-specific handling before C++11+ checks. Use
   SetStorageClassSpec to trigger OpenCL validation and emit version-specific
   error messages.

3. Fix C23 'int auto' and 'constexpr int auto' handling:
   - For 'constexpr int auto': Treat 'auto' as type specifier conflict (don't
     convert to storage class), emit single error message.
   - For 'int auto' without constexpr: Convert 'auto' to storage class specifier
     (no type conflict error), only emit 'illegal storage class' if applicable.

4. Fix template parameter parsing: Skip type name lookup when 'auto' is set
   in template parameter context to avoid false ambiguity errors for
   placeholder variables.

5. Fix concept constraint syntax: Detect 'C<T> auto' pattern and skip type
   conflict detection for concept constraints.

6. Update test expectations: Align error messages and line numbers with
   actual diagnostic locations and behavior.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
@osamakader
osamakader requested a review from Endilll as a code owner July 9, 2026 20:34
@osamakader osamakader changed the title Fix auto with type Fix auto with type in modern C++ Jul 9, 2026
@to268
to268 self-requested a review July 9, 2026 21:34
Comment thread clang/test/SemaCXX/auto-cxx0x.cpp

@Endilll Endilll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make PR title and description more... descriptive?

Comment thread clang/test/CXX/drs/cwg3xx.cpp Outdated
Comment thread clang/test/CXX/drs/cwg3xx.cpp Outdated
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
@osamakader osamakader changed the title Fix auto with type in modern C++ Reject auto combined with type specifiers in C++ Jul 10, 2026
@osamakader
osamakader requested review from Endilll and to268 July 10, 2026 17:25
@osamakader

Copy link
Copy Markdown
Contributor Author

Done.

@Endilll Endilll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to C++ DR tests LGTM

@to268 to268 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regression fix LGTM.
I will try to reland the PR probably this weekend.

@to268
to268 merged commit 72af746 into llvm:main Jul 11, 2026
12 checks passed
@to268

to268 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

The PR looks like to have passed post CI checks (I have merged the PR when the buildbot was offline this morning).
Thank you for the PR!

pedroMVicente pushed a commit to pedroMVicente/llvm-project that referenced this pull request Jul 15, 2026
Follow-up of llvm#166004

- Diagnose C++ declarations that combine `auto` with another type
specifier, such as `auto int` .
- Preserve C/C23 handling where `auto` can still be interpreted as a
storage-class specifier in valid combinations.
- Fix parser disambiguation so `auto Use = 0` treats `Use` as the
declarator name before type lookup, avoiding ambiguous lookup
regressions.

---------

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Comment thread clang/lib/Parse/ParseDecl.cpp
to268 added a commit that referenced this pull request Jul 17, 2026
)

The PR #208552 has introduced a regression where brace initialization
was not taken into account `auto foo{12}`. It was also breaking
`dcl.type.general` p2 rules, which is also now tested.
dyung pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 22, 2026
…#210347)

The PR llvm#208552 has introduced a regression where brace initialization
was not taken into account `auto foo{12}`. It was also breaking
`dcl.type.general` p2 rules, which is also now tested.

(cherry picked from commit d592aa5)
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
to268 added a commit that referenced this pull request Aug 11, 2026
…8552)" and follow-ups commits (#215320)

The initial fix for #164273 had several follow up commits to fix the
initial implementation. This fix induces a lot of regressions and a
refactoring of the area is required in order to fix the issue in a later
release.

This reverts the following commits (from oldest to latest):
72af746
226acaf
d592aa5
34436db
de4b1f5
hulxv pushed a commit that referenced this pull request Aug 12, 2026
…8552)" and follow-ups commits (#215320)

The initial fix for #164273 had several follow up commits to fix the
initial implementation. This fix induces a lot of regressions and a
refactoring of the area is required in order to fix the issue in a later
release.

This reverts the following commits (from oldest to latest):
72af746
226acaf
d592aa5
34436db
de4b1f5
dyung pushed a commit to to268/llvm-project that referenced this pull request Aug 15, 2026
…m#208552)" and follow-ups commits (llvm#215320)

The initial fix for llvm#164273 had several follow up commits to fix the
initial implementation. This fix induces a lot of regressions and a
refactoring of the area is required in order to fix the issue in a later
release.

This reverts the following commits (from oldest to latest):
72af746
226acaf
d592aa5
34436db
de4b1f5
zhangweize9-cyber pushed a commit to zhangweize9-cyber/llvm-project that referenced this pull request Aug 16, 2026
…m#208552)" and follow-ups commits (llvm#215320)

The initial fix for llvm#164273 had several follow up commits to fix the
initial implementation. This fix induces a lot of regressions and a
refactoring of the area is required in order to fix the issue in a later
release.

This reverts the following commits (from oldest to latest):
72af746
226acaf
d592aa5
34436db
de4b1f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants